Submit() and onSubmit()

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

Why the heck doesn't document.aForm.submit() invoke aForm's onSubmit event
handler?
 
G

Grant Wagner

Christopher said:
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 <[email protected]>

* Client-side Javascript and Netscape 4 DOM Reference available at:
*
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/frames.html

* Internet Explorer DOM Reference available at:
*
http://msdn.microsoft.com/workshop/author/dhtml/reference/dhtml_reference_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-developer/upgrade_2.html
 
C

Christopher Benson-Manica

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.
 
T

Thomas 'PointedEars' Lahn

Christopher said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top