Attribute for
<FORM ...>
<FORM ACTION="../cgi-bin/mycgi.pl" NAME="testform" onSubmit="return TestDataCheck()" >
Note that in order to cancel the submit event, the 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:
<SCRIPT TYPE="text/javascript">
<!--
// check that they entered an amount tested, an amount passed,
// and that they didn't pass units than they more than tested
function TestDataCheck()
{
var qtytested = parseInt(document.testform.qtytested.value);
var qtypassed = parseInt(document.testform.qtypassed.value);
var returnval;
if ( (qtytested >= 1) && (qtypassed >= 0) && (qtytested >= qtypassed))
returnval = true;
else
{
alert("must enter the quantity tested and that amount or fewer for quantity passed");
returnval = false;
}
return returnval;
}
// -->
</SCRIPT>
<FORM
ACTION="../cgi-bin/mycgi.pl"
NAME="testform"
onSubmit="return TestDataCheck()"
>
units tested: <INPUT NAME="qtytested" SIZE=3><BR>
units passed: <INPUT NAME="qtypassed" SIZE=3><P>
<INPUT TYPE=SUBMIT VALUE="Submit">
</FORM>
which gives us this form:
|