<html> <head> <title>Form validation</title> <script language="JavaScript"> <!-- script start function validateComplete(formObj) { if (emptyField(formObj.firstName)) alert("Please enter your first name."); else if (emptyField(formObj.lastName)) alert("Please enter your last name."); else if (emptyField(formObj.address1) && emptyField(formObj.address2)) alert("Please enter your address."); else if (emptyField(formObj.city)) alert("Please enter your city or town."); else if (emptyField(formObj.state)) alert("Please enter your state."); else if (emptyField(formObj.email)) alert("Please enter your E-mail address."); else return true;
return false; }
// Check to see if field is empty function emptyField(textObj) { if (textObj.value.length == 0) return true; for (var i=0; i<textObj.value.length; ++i) { var ch = textObj.value.charAt(i); if (ch != ' ' && ch != 't') return false; } return true; }