This page shows how to validate a HTML's FORM elements using JavaScript. You should be familiar with HTML form. If not, see this tutorial: HTML Form Example.
This validation is based on the onSubmit event attached to the FORM tag, like this: <form ... onSubmit="return(f(this));">. The function f is called when user presses the submit button. If the function returns false, then the form will not be sent. In the function f, one can use the dot notation to refer to values of the various input items. For example, if you have a input item named “fA”, and your function f is defined as “f(x) {...}”, then object fA can be referred to as “x.fA” and its value “x.fA.value”. View Source to see the code.
For validation that happens right away as user exit each field, see: FORM Validation by Field
Reference:
Related Essays:
Page created: 2005-12. © 2005 by Xah Lee.