By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,045 Members | 1,384 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,045 IT Pros & Developers. It's quick & easy.

Submit() and onSubmit()

P: n/a
Why the heck doesn't document.aForm.submit() invoke aForm's onSubmit event
handler?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Christopher Benson-Manica wrote:
Why the heck doesn't document.aForm.submit() invoke aForm's onSubmit event
handler?


Because it doesn't.

If you want it to, use Opera 7.0 or 7.1 which had a bug that caused that
behaviour (it's been fixed in 7.21).

The obviously solution is to call the validator code before calling submit():

<a href="noJS.html" onclick="
var f=document.forms['aForm'];
if (validate(f)) f.submit();
">Submit</a>

This would have the same effect as:

<form ... onsubmit="return validate(this);">
<input type="submit" ... />
</form>

--
| Grant Wagner <gw*****@agricoreunited.com>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/...ce/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/a...ence_entry.asp

* Netscape 6/7 DOM Reference available at:
* http://www.mozilla.org/docs/dom/domref/
* Tips for upgrading JavaScript for Netscape 7 / Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #2

P: n/a
Grant Wagner <gw*****@agricoreunited.com> spoke thus:
Why the heck doesn't document.aForm.submit() invoke aForm's onSubmit event
handler?
Because it doesn't.
I think I was misunderstood - I *know* it doesn't, I was curious about the
rationale.
The obviously solution is to call the validator code before calling submit():


I suppose, although I still wish my original plan were possible.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 20 '05 #3

P: n/a
Christopher Benson-Manica wrote:
Grant Wagner <gw*****@agricoreunited.com> spoke thus:
Why the heck doesn't document.aForm.submit() invoke aForm's onSubmit event
handler?

Because it doesn't.


I think I was misunderstood - I *know* it doesn't, I was curious about the
rationale.


The event does not fire here because the submit is initiated by the
author/programmer, not by the user. But if you need to call the event
handler explicitely, use

document.forms['aForm'].onsubmit();

in IE 6.0 and Mozilla/5.0, since it is implemented as an anonymous
function there. (Note the use of the standards-compliant `forms' collection.)
PointedEars
Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.