472,789 Members | 1,089 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 6551
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
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
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
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
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
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
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
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
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
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
by: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.