473,399 Members | 3,038 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,399 software developers and data experts.

onClick, onChange problems with form submit

I have a table where all the TRs have an onClick handler registered.
One (and only one) of the rows has 2 text input boxes, where each
textbox has an onChange handler registered. Both the onClick and
onChange handlers do some minor manipulation of form data (although
they work on different form elements). If the onChange event fires, I
need the form to be submitted. If the onClick event fires for a TR, I
also need the form to be submitted. What I am seeing is that if I
change the value in a text box, then click on a row, the onChange
handler runs, performs the form submission, and sometimes onClick also
runs and does a form submission as well. This leads to unpredictable
results.

Ideally I'd like some way to be able to execute onChange from start to
finish, then onClick from start to finish, then submit my form (just
once of course). So far I haven't figured out a way to do this. Does
anyone have any suggestions for how to accomplish this?

Thanks in advance,
Andy
Jul 23 '05 #1
2 7010
Lee
Andy Goldstein said:

I have a table where all the TRs have an onClick handler registered.
One (and only one) of the rows has 2 text input boxes, where each
textbox has an onChange handler registered. Both the onClick and
onChange handlers do some minor manipulation of form data (although
they work on different form elements). If the onChange event fires, I
need the form to be submitted. If the onClick event fires for a TR, I
also need the form to be submitted. What I am seeing is that if I
change the value in a text box, then click on a row, the onChange
handler runs, performs the form submission, and sometimes onClick also
runs and does a form submission as well. This leads to unpredictable
results.

Ideally I'd like some way to be able to execute onChange from start to
finish, then onClick from start to finish, then submit my form (just
once of course). So far I haven't figured out a way to do this. Does
anyone have any suggestions for how to accomplish this?


Instead of simply submitting the form, first check to see if it has
already been scheduled for submission. If not, use setTimeout() to
schedule submission after a 100ms delay.

Jul 23 '05 #2
Andy Goldstein wrote:
I have a table where all the TRs have an onClick handler registered.
It would be better if only the parent TABLE element would have that
handler and you would use event bubbling to handle that event.
One (and only one) of the rows has 2 text input boxes, where each
textbox has an onChange handler registered.
While I would recommend that you then give that TR element an ID to
tell it from the others in the event listener, I remind you that TABLE
elements should not be used for layout purposes alone; use CSS for
that instead.
Both the onClick and onChange handlers do some minor manipulation of
form data (although they work on different form elements). If the
onChange event fires, I need the form to be submitted.
You certainly do not want that. Consider that the user made a typo, is
recognizing that after the control is updated and will be now disallowed
to correct it. Users are used to the behavior that a form is submitted
when *they* _chose_ to submit it, using the submit button. (You *have*
thought of a submit button and thus of users without client-side script
support, have you not?)
If the onClick event fires for a TR, I also need the form to be
submitted.
A similar problem here. What if someone wants to use his pointing
device (usually a mouse) to copy/paste some information? The "click"
event would fire then.
What I am seeing is that if I change the value in a text box, then
click on a row, the onChange handler runs, performs the form submission,
and sometimes onClick also runs and does a form submission as well.
This leads to unpredictable results.
Which is why you should let it be.
Ideally I'd like some way to be able to execute onChange from start to
finish, then onClick from start to finish, then submit my form (just
once of course).
There is nothing ideal of this approach.
So far I haven't figured out a way to do this. Does
anyone have any suggestions for how to accomplish this?


Do not do this.
HTH

PointedEars
Jul 23 '05 #3

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

Similar topics

5
by: ddt_rock | last post by:
Hello, everyone! I have a problem with Netscape. I want to submit form from <A> tag <form name="f1" method="post" action="TTT.htm"> <a href="javascript:document.f1.submit();"> Test </a>
2
by: Jason Novotny | last post by:
Hi, I'm trying to create a listbox using <select> HTML tags that can do a form submit when an option in the list is selected. So far this works, function MySelectSubmit() {...
1
by: Tony Hedge | last post by:
Hello, I hope some one can answer this for me. I am using .NET version 1.0 on Windows 2000Pro and I am getting an error when doing a form submit from an HTML control. Please look at the...
5
by: sams | last post by:
I've seen this covered before, but I just don't understand Java very well. I apologize if this is a repeat. Basically, I need a text/java style submit form with multiple hidden fields. It would...
8
by: shandain | last post by:
Ok, I have done this a million times, and I can't get this to work... I hope I am just being an idiot and missing something... but I can't see it... so please call me an idiot and tell me what it...
2
by: Hongyu | last post by:
I am trying to implement a simple JavaScript of redirecting my window to a new URL upon clicking a submit button. This is an easy task except when I have to put an input type='submit' in front of...
7
Fary4u
by: Fary4u | last post by:
Hi how to find the return value if it's wrong parameters I need to STOP form on false statement with out submitting form () <input onchange="preview(this); this.form.submit()"> I’ve tried...
1
by: gbezas | last post by:
Hi All, I have added an event handler to redirect form.submit() to a newSubmit() method that I have defined (which does some additional processing before submitting the form). Additionally I...
14
by: white lightning | last post by:
How to have <select onchange="this.form.submit()"and also a Submit button on one form? I have something like this: <form action="<?php $_SERVER; ?>" method="post"...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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...
0
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,...

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.