473,385 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

onSubmit not working

Hi,

I have a form with onSubmit embedded in the <form>
tag. The form is submitted programatically through
javascript [ie... form.submit()]. While the form submits fine, nothing
I'm doing seems to get it to also register the code in the onSubmit event.
Any suggestions as to why this is happening or how to resolve it?

-Stu
Jul 20 '05 #1
4 18664
Stuart Wexler wrote:
Hi,

I have a form with onSubmit embedded in the <form>
tag. The form is submitted programatically through
javascript [ie... form.submit()]. While the form submits fine, nothing
I'm doing seems to get it to also register the code in the onSubmit event.
Any suggestions as to why this is happening or how to resolve it?

-Stu


Yes, this is correct behavior. the onsubmit event does not fire if you call
document.forms['yourForm'].submit();

The way to get around this is to add the onsubmit validation test as a
condition before calling submit(). So instead of:

<a href="#"
onclick="document.forms['yourForm'].submit();return false;">Submit</a>

you would use:

<a href="#"
onclick="
var f = document.forms['yourForm'];
if (validate(f)) {
f.submit();
}
return false;
">Submit</a>

Indentation and newlines for readability only, it can all go on a single line,
or be put in a function and called from the onclick event.

--
| 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 6/7 and Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #2
In article <C_********************@comcast.com>, St*******@comcast.net
enlightened us with...
Hi,

I have a form with onSubmit embedded in the <form>
tag. The form is submitted programatically through
javascript [ie... form.submit()]. While the form submits fine, nothing
I'm doing seems to get it to also register the code in the onSubmit event.
Any suggestions as to why this is happening or how to resolve it?


For whatever reason, onSubmit won't execute from form.submit(). I had
that problem, too. I never found out if it was a bug or just one of
those things that doesn't make any sense.
You have to call the function that onSubmit calls from the same function
that calls form.submit().

-------------------------------------------------
~kaeli~
Black holes were created when God divided by 0.
Not one shred of evidence supports the notion
that life is serious.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #3
On Mon, 21 Jul 2003 17:36:06 GMT, Grant Wagner
<gw*****@agricoreunited.com> wrote:
Stuart Wexler wrote:
Hi,

I have a form with onSubmit embedded in the <form>
tag. The form is submitted programatically through
javascript [ie... form.submit()]. While the form submits fine, nothing
I'm doing seems to get it to also register the code in the onSubmit event.
Any suggestions as to why this is happening or how to resolve it?

-Stu


Yes, this is correct behavior. the onsubmit event does not fire if you call
document.forms['yourForm'].submit();


It's documented correct in IE, but to standards it's wrong, a lot of
pages would break right now if the correct spec following was done...

I'd play safe and always call onsubmit manually, then remove it, then
submit.

Jim.
--
comp.lang.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4
Jim Ley wrote:
On Mon, 21 Jul 2003 17:36:06 GMT, Grant Wagner
<gw*****@agricoreunited.com> wrote:
Stuart Wexler wrote:
Hi,

I have a form with onSubmit embedded in the <form>
tag. The form is submitted programatically through
javascript [ie... form.submit()]. While the form submits fine, nothing
I'm doing seems to get it to also register the code in the onSubmit event.
Any suggestions as to why this is happening or how to resolve it?

-Stu


Yes, this is correct behavior. the onsubmit event does not fire if you call
document.forms['yourForm'].submit();


It's documented correct in IE, but to standards it's wrong, a lot of
pages would break right now if the correct spec following was done...

I'd play safe and always call onsubmit manually, then remove it, then
submit.

Jim.


I asked a while back about this and received a reply at the time that seemed to
indicate onsubmit should not fire when submit() is called, but it's certainly
possible the person responding was incorrect.

As for browser support, IE 4+, Netscape 3+ and Opera up to 6 did not call onsubmit
when submit() was invoked. It seems that Opera 7.x does, which can lead to all
sorts of nasty surprises if you both manually call the validation routine and have
it called as part of an onsubmit event.

So you're right, remove the onsubmit event from the form and always call it
manually if you are invoking submit() anywhere. Better yet, avoid calling submit()
directly wherever possible.

--
| 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 6/7 and Mozilla
* http://www.mozilla.org/docs/web-deve...upgrade_2.html
Jul 20 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Varun | last post by:
Hi There, I have a form("myRequest.asp") and the values from it are retrieved into the page ("output_Print.asp") on which I have two buttons('Save As Complete' and 'Save As Incomplete'). When the...
1
by: bbxrider | last post by:
the onreset is working but problem somewhere in the onsubmit or the function it calls. i have abbreviated the called verfiy function for now just to get the basic onsubmit part working basically...
4
by: Kai Grossjohann | last post by:
I have two frames. Frame "search" contains a search form specifying an onsubmit action like so: <form ... onsubmit="foo();"> ... </form> The other frame contains a <img ......
3
by: Simon Wigzell | last post by:
My client has many forms on his Business website. They all use the "onsubmit" verification method e.g. <form ......... onsubmit="return FormValidator(this);"> <script> function...
12
by: micahl0180 | last post by:
Ok, I am having trouble with the code below, but cannot seem to find the problem. When I run it, it says Object Expected" and points me to line 31: <form action="" method="post" name="payroll"...
2
by: OtisUsenet | last post by:
Hello, I am trying to call Javascript from FORM's onSubmit, and return false, so the form is not actually submitted. Normally I can just add 'return false;' to onSubmit to accomplish this, like...
8
by: Chris Kettenbach | last post by:
I have a function that validates a text box. Is there anyway to run that function on submit and if it returns false to cancel the submit. Any ideas. Thanks Guys! This group is awesome. Thanks,...
4
by: Tina | last post by:
I have some javascript that I want executed whenever my form is subitted so I put onSubmit= "return myfunction();" in my <form clause on my aspx page. If the user hits a button the javascript...
2
scubak1w1
by: scubak1w1 | last post by:
Hello, I am building a form that collects some data about a file and throws it into a PosgreSQL database and also allows the user to upload and process the file using PHP's $_FILES... i.e.,...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.