Node.js examples for HTML:Form
Used by the login screen to validate user/pass are entered.
function validateRequired(form) { var bValid = true; var focusField = null; var i = 0; var fields = new Array(); oRequired = new required(); for (x in oRequired) { if ((form[oRequired[x][0]].type == 'text' || form[oRequired[x][0]].type == 'textarea' || form[oRequired[x][0]].type == 'select-one' || form[oRequired[x][0]].type == 'radio' || form[oRequired[x][0]].type == 'password') && form[oRequired[x][0]].value == '') { if (i == 0) focusField = form[oRequired[x][0]]; // ww w . j av a 2 s .c o m fields[i++] = oRequired[x][1]; bValid = false; } } if (fields.length > 0) { focusField.focus(); alert(fields.join('\n')); } return bValid; }