If you must validate a FORM before it is sent to the server, you will have to depend on the browser to faithfully execute the submit() method of the form object. Most Mozilla 3.x/4.x browsers support this method.
For example we can set up a function called "jsSendForm()" that takes a form object as an argument. So if the FORM element name is "frmOne" we can then call:
jsSendForm(window.document.frmOne)
or, if frmOne is the only form in the document, we alternatively have:
jsSendForm(window.document.forms[0])
or, if frmOne is being called from an event (usually the onClick event) in an element inside frmOne we have:
jsSendForm(this.form)
where jsSendForm() looks like this:
function jsSendForm(vForm) {
vFrmValid
//Form validation code goes here.
//If validation fails, vFrmValid=False
if (vFrmValid) {
vForm.submit
window.document.close
}
else { \\\\Do something for invalid data. }
}
One technique is to call this function from the onClick event of the INPUT element. Instead of using an INPUT element of TYPE "submit" we can use the following:
<INPUT
TYPE=button
VALUE="Send"
onCLick="jsSendForm(this.form)">
NOTE: Some browsers (namely some Netscape browsers) will ignore the submit() method of a form object where the FORM elements ACTION property contains "mailto:" protocol. This is done for security reasons.