473,327 Members | 1,936 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,327 software developers and data experts.

event handler problem in large complex form

I find that in a large form (especially if there is a table within the
form?) that the form is submitted to my server-side script even when a
JavaScript 'onsubmit' event handler returns 'false'.

does any one else have this problem, and is there a work-round?

--
Arthur Rusdell-Wilson
Jul 23 '05 #1
8 1310


Arthur Rusdell-Wilson wrote:
I find that in a large form (especially if there is a table within the
form?) that the form is submitted to my server-side script even when a
JavaScript 'onsubmit' event handler returns 'false'.


Does that happen with one particular browser? Or with different ones?
Is there perhaps a script error happening so that the return false
statement is not reached?

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
"Arthur Rusdell-Wilson" <ar****@kitekonsultants.co.uk> wrote in message
news:db*******************@news.demon.co.uk...
I find that in a large form (especially if there is a table within the
form?) that the form is submitted to my server-side script even when a
JavaScript 'onsubmit' event handler returns 'false'.

does any one else have this problem, and is there a work-round?

--
Arthur Rusdell-Wilson


It's likely you aren't returning the value returned from the JavaScript
function to the event:

<form ... onsubmit="validate(this);">

The above won't ever stop the form submission even if the function is
defined as:

function validate() { return false; }

In order for the function to prevent form submission, you must return
the value to the event:

<form ... onsubmit="return validate(this);">

If you have this, and you've verified that false (not "false") is
actually being returned (using <form ...
onsubmit="alert(validate(this));">), then it's a browser implementation
bug and there won't be any work-around short of changing browsers.

I doubt very much it is a browser implementation bug, and instead one of
the two possibilities I listed:

1) you aren't returning the value to the event
2) you are returning the string "false" instead of the boolean false

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #3
VK
> I find that in a large form (especially if there is a table within the
form?) that the form is submitted to my server-side script even when a
JavaScript 'onsubmit' event handler returns 'false'.
does any one else have this problem, and is there a work-round?


I encountered it several times (but very rarely). It was always
connected with too long delay before you approve/cancel the bubble.
Always was helped by optimising the code (so your decision would come
out quickly). One of undescribed yet ghosts of JavaScript (like orphane
scripts). Never happens on primitive events like onclick/mousevove/etc.

Form submission / window closure / unload - the most probable places to
meet them. I call this "speedy bubbles", you may too if you want :-)

I guess it's a part of interface protection, so you couldn't lock user
on one page by simply putting each onsubmit/onbeforeunload/onload on
some endless process. Just an amateur guess...

Get the fat out of you script, it should help right away. Unless the
problem is im something else.

Jul 23 '05 #4

First off, give your page a document type, a DTD, say html4.1 strict dtd
and then validate, chances are your page is malformed and Form is split by
some unclosed opened element in it:

<form> <input> <input> <table> .....</form> </table>
really in quirk mode will cut off the 1st Form at the <table> part as it
never closed IN IT, and more than likely will render a 2nd orphan Form
from the fragment, cutting off any children from the 1st Form. I've seen
such and JS does report that because you're eventing an element that's cut
off from the Parent element you think it belongs to.
<FORM> <input> <button> <select></select> <ANYELEMEENT> .....
</ANYELEMENT></form>

is the proper way and will keep all Form children with its parent.
Danny

On Tue, 12 Jul 2005 08:55:13 -0700, Arthur Rusdell-Wilson
<ar****@kitekonsultants.co.uk> wrote:

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #5
I think you are probably right. I worked on that assumption, and everything
now works ok. However I did find one or two other little bugs as I was doing
this, so not absolutely sure. Anyway, I have an approach now for avoiding
this problem in the future.

--
Arthur Rusdell-Wilson
"VK" <sc**********@yahoo.com> wrote in message
news:11*********************@g49g2000cwa.googlegro ups.com...
I find that in a large form (especially if there is a table within the
form?) that the form is submitted to my server-side script even when a
JavaScript 'onsubmit' event handler returns 'false'.
does any one else have this problem, and is there a work-round?


I encountered it several times (but very rarely). It was always
connected with too long delay before you approve/cancel the bubble.
Always was helped by optimising the code (so your decision would come
out quickly). One of undescribed yet ghosts of JavaScript (like orphane
scripts). Never happens on primitive events like onclick/mousevove/etc.

Form submission / window closure / unload - the most probable places to
meet them. I call this "speedy bubbles", you may too if you want :-)

I guess it's a part of interface protection, so you couldn't lock user
on one page by simply putting each onsubmit/onbeforeunload/onload on
some endless process. Just an amateur guess...

Get the fat out of you script, it should help right away. Unless the
problem is im something else.

Jul 23 '05 #6
See my reply to VK

--
Arthur, on behalf of Kite Konsultants

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:42***********************@newsread2.arcor-online.net...


Arthur Rusdell-Wilson wrote:
I find that in a large form (especially if there is a table within the
form?) that the form is submitted to my server-side script even when a
JavaScript 'onsubmit' event handler returns 'false'.


Does that happen with one particular browser? Or with different ones?
Is there perhaps a script error happening so that the return false
statement is not reached?

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 23 '05 #7
The problems you identify were not those that I had. I believe VK has the
answer, see my reply to his.

--
Arthur, on behalf of Kite Konsultants

"Grant Wagner" <gw*****@agricoreunited.com> wrote in message
news:0m**************@news2.mts.net...
"Arthur Rusdell-Wilson" <ar****@kitekonsultants.co.uk> wrote in message
news:db*******************@news.demon.co.uk...
I find that in a large form (especially if there is a table within the
form?) that the form is submitted to my server-side script even when a
JavaScript 'onsubmit' event handler returns 'false'.

does any one else have this problem, and is there a work-round?

--
Arthur Rusdell-Wilson


It's likely you aren't returning the value returned from the JavaScript
function to the event:

<form ... onsubmit="validate(this);">

The above won't ever stop the form submission even if the function is
defined as:

function validate() { return false; }

In order for the function to prevent form submission, you must return
the value to the event:

<form ... onsubmit="return validate(this);">

If you have this, and you've verified that false (not "false") is
actually being returned (using <form ...
onsubmit="alert(validate(this));">), then it's a browser implementation
bug and there won't be any work-around short of changing browsers.

I doubt very much it is a browser implementation bug, and instead one of
the two possibilities I listed:

1) you aren't returning the value to the event
2) you are returning the string "false" instead of the boolean false

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq

Jul 23 '05 #8
Thanks, this was not the problem. See my reply to VK

--
Arthur, on behalf of Kite Konsultants

"Danny" <da*******@bluebottle.com> wrote in message
news:1121224720.43ad5d22940ff6a748c56a48f7a65572@t eranews...

First off, give your page a document type, a DTD, say html4.1 strict dtd
and then validate, chances are your page is malformed and Form is split by
some unclosed opened element in it:

<form> <input> <input> <table> .....</form> </table>
really in quirk mode will cut off the 1st Form at the <table> part as it
never closed IN IT, and more than likely will render a 2nd orphan Form
from the fragment, cutting off any children from the 1st Form. I've seen such and JS does report that because you're eventing an element that's cut
off from the Parent element you think it belongs to.
<FORM> <input> <button> <select></select> <ANYELEMEENT> .....
</ANYELEMENT></form>

is the proper way and will keep all Form children with its parent.
Danny

On Tue, 12 Jul 2005 08:55:13 -0700, Arthur Rusdell-Wilson
<ar****@kitekonsultants.co.uk> wrote:

--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/

Jul 23 '05 #9

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

Similar topics

18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
1
by: Dan | last post by:
All, I have a form with a check box on it for which I have implemented a CheckedChange event. The form is the front end of a complex data entry system. When I load the form I check for...
0
by: Francois Malgreve | last post by:
Hi all, I have a more or less complex form with a few buttons and a few input fields. One of my my input field ( a TextBox) I have an event handler for the TextChanged event. What I want is...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
1
by: Earl Teigrob | last post by:
I did a ton of searching to try and find a simple solution to this issue and finally wrote my own, which I am sharing with everyone. In my searching, I did find a very complete and robust solution at...
4
by: Lars Netzel | last post by:
Is there any way to add some code that will happen in every single Event that i raised in a form? I have a Total field in the bottom of a pretty complex page and I think it's kind of "Dirty" to...
2
by: Robert | last post by:
Hello javascript group readers, I have a question regarding how to prevent memory leaks in Internet Explorer when using closures. I already knew about the circular reference problem, and until...
1
by: kaczmar2 | last post by:
I have an ASP.NET page where controls are created dynamically, and I have an issue where one event handler creates another set of controls, and then adds event handlers to those controls. The...
10
by: =?Utf-8?B?UmljaGFyZCBCeXNvdXRo?= | last post by:
Hi In my app I have a SplashScreen, a login form and a main form. On launching the app, I'd like to show the SplashScreen while reading config files and attempting a database connection. I show...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.