473,467 Members | 1,436 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Submit() and onSubmit()

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
3 12194
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: jeff | last post by:
Hello, I have a form that submits it's values to a pop-up window. I've simplied the code: <form name="formname" action="action.php" target="windowName" method="post" onsubmit="window.open('',...
8
by: Syed Ali | last post by:
Hello, I have 1 HTML form with 4 submit buttons and 10 textfield entry areas. If submit button1 is pressed I need to make sure that all 10 textfield entries have been filled before submitting...
3
by: Matt | last post by:
When the user click the submit button in myform.asp, then it will invoke the javascript to check the form data. I want to know if we need document.myform.submit(); ?? Because even I comment it...
8
by: horos | last post by:
hey all, Ok, a related question to my previous one on data dumpers for postscript. In the process of putting a form together, I'm using a lot of placeholder variables that I really don't care...
4
by: gimme_this_gimme_that | last post by:
Hi, This is sort of a : How to build a Yes/No dialog box qquestion. Or perhaps a question about getting javascript variables from a pop-up window and processing them on a submit. This is...
2
by: The Crow | last post by:
i have to catch submit event of the form contained in the asp.net webform. when a button on the page clicked, it works ok, but when i call form.submit() or linkbutton vs. calls __doPostBack() ,...
8
by: Ed Jay | last post by:
Is there a way to use 'document.form.submit()' to submit a form to a url other than that specified in the Form element? -- Ed Jay (remove M to respond by email)
3
by: Taras_96 | last post by:
Hi everyone, I've got a rather unconventional architecture that I'm having problems with... I have a form called "searchForm", that has an input of type "submit" (with name = "submitButton...
10
by: ljlolel | last post by:
So.. I have a form that submits to an ASP.net site made in C-sharp. The ASP site is not mine, i do not have the server side code. When I submit from my form by pressing the Submit button, I get...
3
by: prodizy | last post by:
Hi, In Firefox, what's the best way of tracking the form submit? The following are two ways I tried, but they won't work if the form is submitted through JavaScript. Method 1: using the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.