This form uses some basic OO-style JavaScript to validate a field has a value before it can be submitted.
Here's the code for the Validator Obejct:
var Validator = { version: '1.0.0', init: function(frm){this.form=document.forms[frm]}, validate: function(fld){ alert( "Form Validator Version "+this.version+"\n\n"+ "The field called \"" + fld + "\" " + ( (this.form[fld].value=="")?"failed":"passed" ) + " validation" ) return this.form[fld].value!=""; } }
When the page loads we call the Validator's init() method, which gets a handle on the form we are working with.
When the form is submitted we ask the Validator to check a field for a value. If it's blank the form doesn't submit. Simple.