Entry
Why is my onsubmit handler not called when I submit the form with js (document.formName.submit())?
Apr 19th, 2000 16:00
Martin Honnen,
It seems that someone decided that if you use JavaScript to submit that
you can call the onsubmit handler yourself if you want it called:
if (document.formName.onsubmit())
document.formName.submit()
See it as an advantage of having the flexibility to decide whether to
call onsubmit or not when submitting with JavaScript.
Note that if you have a submit button you can also call
document.formName.submitButtonName.click()
to submit with calling onsubmit first.
Here is an example of both approaches:
<FORM NAME="formName"
ONSUBMIT="return confirm('submit?')"
>
<INPUT TYPE="text" NAME="fieldName" VALUE="Kibology">
<INPUT TYPE="submit" NAME="submit0">
</FORM>
<A HREF="javascript:
if (document.formName.onsubmit())
document.formName.submit();
void 0"
>
submit with js
</A>
|
<A HREF="javascript:
document.formName.submit0.click();
void 0"
>
call click on submit button
</A>