Checking Elements on a Form
<html> <head> <title>Online Registration</title> <SCRIPT LANGUAGE="JavaScript"> <!-- function checkFields() { var num = document.form1.elements.length var validFlag = true for (var i=0; i<num; i++) { if ((document.form1.elements[i].value == null || document.form1.elements[i].value == "") && (typeof document.form1.elements[i] != 'submit' || typeof document.form1.elements[i] != 'reset')){ validFlag = false; alert("The " + document.form1.elements[i].name + " field is blank.") break ; } } return validFlag; } // --> </SCRIPT> </head> <body> <form name="form1" method="POST" onSubmit="return checkFields()"> <p>Username:<br> <input type=text size=25 maxlength=256 name="Username"> <br> Email address: <strong><br></strong> <input type=text size=25 maxlength=256 name="EmailAddress"></p> <input type=submit value="Register"> <input type=reset value="Clear"> </form> </body> </html>