473,499 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form onsubmit

If you have an onsubmit event handler defined for a form, it doesn't seem to
trigger if you manually call the .submit() method of the form object. Is
there any way you can make sure that code is executed?

thnx,
Christoph
Mar 14 '08 #1
2 6586
On Mar 14, 10:15 am, "Sorrow" <jcbo...@yahoo.comwrote:
If you have an onsubmit event handler defined for a form, it doesn't seem to
trigger if you manually call the .submit() method of the form object.
Most browsers work that way, but some will fire the submit event when
the form's submit method is called programatically (e.g. Opera 7,
perhaps later versions too, I can't test it right now).

Is
there any way you can make sure that code is executed?
Call it with the function that calls submit. You will need to deal
with stopping the onsubmit handler from firing twice in some browsers
- perhaps if it runs successfully, you can remove it before calling
submit().
<script type="text/javascript">

function doSubmit(el) {
var form = el.form;
if (typeof form.onsubmit == 'function') {
if (form.onsubmit() !== false) {
form.submit();
}
}
}

</script>

<form onsubmit="alert('hey'); return false;">
<div><input type="button" value="submit onclick"
onclick="doSubmit(this);"></div>
</form>

--
Rob
Mar 14 '08 #2
SAM
RobG a écrit :
>
Call it with the function that calls submit. You will need to deal
with stopping the onsubmit handler from firing twice in some browsers
- perhaps if it runs successfully, you can remove it before calling
submit().
<script type="text/javascript">

function doSubmit(el) {
var form = el.form;
if (typeof form.onsubmit == 'function') {
if (form.onsubmit() !== false) {
I do not understand at all why :
form.submit();
now runs as waited ...

or is it the form.onsubmit() that fires ?
}
}
}
Ha ! it is :

function doSubmit(el) {
var form = el.form;
form.onsubmit();
}

that does the job (in my Fx)
>
</script>

<form onsubmit="alert('hey'); return false;">
<div><input type="button" value="submit onclick"
onclick="doSubmit(this);"></div>
</form>
--
sm
Mar 14 '08 #3

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

Similar topics

7
2962
by: greg brant | last post by:
i have a form made up of 2 file inputs and a submit button.. the imputs are to upload images, namley jpeg's for a e-greatings thing im working on. this only works with jpegs so i have a script...
3
24509
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('',...
12
2436
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" ...
3
12115
by: n3mtkj3mzsir0cy | last post by:
I have created web pages that do client-side form validation using the onclick directive. E.g., <form action=other_page.cgi method=post> Enter your age: <input name=age> <input type="submit"...
2
8540
by: JHB | last post by:
Hi, How can I do a location.replace when I use a form, like when I use a href? This works. <a href="Ny HTML-side20.htm"; method="post" id="frm" name="BrugerHovedSide"...
2
6459
by: Sean Dockery | last post by:
Which is the following is correct? a) <form ... onSubmit="return checkData()"> b) <form ... onSubmit="return checkData();"> c) <form ... onSubmit="checkData()"> d) <form ......
10
6591
by: iam247 | last post by:
Hi In my prototype asp page (with no javascript and no password validation, I have a registration form with the following action: <form name="form" method="post" action="RegDetails.asp"> ...
1
1926
by: vunet | last post by:
I write a JS library component which is applied to every form on a webpage. The component does something before it submits the form. Now, let's say user has his own onSubmit() handlers returning...
2
4757
by: rudiedirkx | last post by:
Gents, I have a problem (only in Safari) with the onsubmit in webforms. This topic covers the same subject: http://bytes.com/topic/javascript/answers/166542-onsubmit-safari but not as detailed as...
0
7134
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
7180
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,...
0
7225
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6901
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...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3101
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
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 ...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.