
| <SCRIPT>
/****** Simple Validation Checking ******///--------------------------------------------------------------- function ValidateInput(form) {var LB = "\n"; // LB represents a Line Break var msgHdr = "Please fill out your:" + LB + LB; // Alert Header Message // The message the User will see informing her or him of any empty fields that are required var msg = ""; // We are simply checking to see if the field is empty or not // if the field is empty then add the Field Information to the msg variable // NOTE: we could have also used -- if (form.First.value.length == 0) if (form.First.value == "") msg += "First Name" + LB; if (form.Last.value == "") msg += "Last Name" + LB; if (form.Address1.value == "") msg += "Address" + LB; // Note: Address2 is not mandatory if (form.City.value == "") msg +=
"City" + LB; // this is where you would call another function to take of this particular situation if (form.Postal.value == "") msg += "Postal Code" + LB; // Verify that Age is a numeric w/ a value greater than 0 by converting it to an integer: if (form.Age.value == "" || parseInt(form.Age.value) == 0) msg += "Age" + LB; // Make sure that the user makes a selection from the Income drop-down list: // the first selection is empty, so the user has to select something other than the first selection if (form.Income.options[form.Income.selectedIndex].value == "0") msg += "Income" + LB; // Make sure that a Female or Male radio button has been selected: // NOTE: The if statements says if male and the female radio buttons are not checked // then add that information to the msg variable // OR form.elements[9].checked == false && form.elements[10].checked == false if (form[9].checked == false && form[10].checked == false) msg += "Sex" + LB; // Display an alert if any of the input is missing: // the msg variable will only be empty if all the fields are filled out, // if not, the msg variable will contain the fields that are empty if (msg.length > 0){ // if the msg string is not empty, meaning some fields were left empty alert(msgHdr + msg); // return the document and the results back to the User // instead of "Submitting" the Form's Information to the server return false; } // "Submit" the Form's Information to the server for CGI processing. else return true; } /****** End of Validation Checking ******/< /SCRIPT><BODY> <FORM |