Attribute for <FORM ...>onSubmit = "script command(s)"
onSubmit = "script command(s)"
|use it, but don't rely on it|
<FORM ACTION="../cgi-bin/mycgi.pl" NAME="testform" onSubmit="return TestDataCheck()" >
Note that in order to cancel the submit event, the
"return" indicates that the value of the expression should be returned to the submit routine. If the expression evaluates to false, the submit routine is cancelled; if it is true, the submit routine goes forward.
Let's look at the full code for our example. Consider a form that a technician uses to enter how many production units have been tested, and how many units passed the tests. For a form like this we might want to check:
- if one or more units were tested
- if zero or more units were passed
- if no more units were passed than were tested
Here is the full code to do this:
which gives us this form: