Login field validator I have this basic JavaScript that, using a constructor, validates the form where the login fields can't be empty. All this WITHOUT using any JS libraries.

function Validator(txtbox) {
    this.txtbox = txtbox;
}

var validator = new Validator([ "username", "password"]);

Validator.prototype.validate = function(form) {
    for(var i = 0, l=this.txtbox.length; i &lt; l; i++) {
        var status = document.getElementById("status-msg");
        if (form[this.txtbox[i]].value == 0) {
            status.innerHTML="The " + form[this.txtbox[i]].name + " is empty";
            status.style.display = "inline-block"
            status.className = "error";
            return false;
        }
        else {
             status.innerHTML="Login successful";
            status.style.display = "inline-block"
             status.className = "success";
        }
    }
}

function runValidate(form) {
    validator.validate(form);
}


I'm wondering how I can make it more efficient or better.
Why not add some JSDoc to your code:

/**
*@constructor
*@param {Array} txtbox - An array of whatever
*@returns {Validator}
*/
function Validator(txtbox) {
    /**
    *@private
    */
    this.txtbox = txtbox;
}

var validator = new Validator([ "username", "password"]);

/**
*@public
*@memberOf Validator.prototype
*@param {Form} form - The form holding the login information
*/
Validator.prototype.validate = function(form) {
    for(var i = 0, l=this.txtbox.length; i &lt; l; i++) {
        var status = document.getElementById("status-msg");
        if (form[this.txtbox[i]].value == 0) {
            status.innerHTML="The " + form[this.txtbox[i]].name + " is empty";
            status.style.display = "inline-block"
            status.className = "error";
            return false;
        }
        else {
             status.innerHTML="Login successful";
            status.style.display = "inline-block"
             status.className = "success";
        }
    }
}

function runValidate(form) {
    validator.validate(form);
}