473,396 Members | 2,002 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,396 software developers and data experts.

Clicking a row in a table affects the control

I have a script that will cycle thru a form and add a handler to the row so
that if it is clicked it will check the checkbox within the row with
basically cb.checked = !cb.checked. This part works great except if you
click on the checkbox itself. It will also trigger the row. Am I missing an
obvious way of how to avoid that? Reason, like I was saying. Clicking on the
row toggles the checkbox but if the checkbox is unchecked and you check it,
it will instantly go back to unchecked making the appearance it was never
checked. Hence, it's always unchecked unless you hit the row. I need to come
up with something I can add into the code that looks at the checkbox somehow
to avoid this. It's as if the handler would need to see if it itself was
clicked or the control within it itself (the row).

Any ideas?
Thanks

Steffan

Sep 5 '07 #1
3 1498
On Sep 5, 1:01 pm, "Steffan A. Cline" <stef...@hldns.comwrote:
I have a script that will cycle thru a form and add a handler to the row so
that if it is clicked it will check the checkbox within the row with
basically cb.checked = !cb.checked. This part works great except if you
click on the checkbox itself. It will also trigger the row. Am I missing an
obvious way of how to avoid that? Reason, like I was saying. Clicking on the
row toggles the checkbox but if the checkbox is unchecked and you check it,
it will instantly go back to unchecked making the appearance it was never
checked. Hence, it's always unchecked unless you hit the row. I need to come
up with something I can add into the code that looks at the checkbox somehow
to avoid this. It's as if the handler would need to see if it itself was
clicked or the control within it itself (the row).
1. Add a handler to the checkbox that cancels bubbling.

2. In the row handler, see if the target was the checkbox (or its
label) and don't toggle the checked property if it is.

I think 2. may be the better option.
--
Rob

Sep 5 '07 #2
in article 11**********************@k79g2000hse.googlegroups. com, RobG at
rg***@iinet.net.au wrote on 9/5/07 3:22 AM:
On Sep 5, 1:01 pm, "Steffan A. Cline" <stef...@hldns.comwrote:
>I have a script that will cycle thru a form and add a handler to the row so
that if it is clicked it will check the checkbox within the row with
basically cb.checked = !cb.checked. This part works great except if you
click on the checkbox itself. It will also trigger the row. Am I missing an
obvious way of how to avoid that? Reason, like I was saying. Clicking on the
row toggles the checkbox but if the checkbox is unchecked and you check it,
it will instantly go back to unchecked making the appearance it was never
checked. Hence, it's always unchecked unless you hit the row. I need to come
up with something I can add into the code that looks at the checkbox somehow
to avoid this. It's as if the handler would need to see if it itself was
clicked or the control within it itself (the row).

1. Add a handler to the checkbox that cancels bubbling.

2. In the row handler, see if the target was the checkbox (or its
label) and don't toggle the checked property if it is.

I think 2. may be the better option.

Rob,

Have an example of either?

Here is what I current an using to add the handler to the row
row.onclick = function () {
var x = getControl(this);
if( x )
{
switch( x.type )
{
case( "radio" ) : this.style.backgroundColor = selectedColor;
x.checked = true;
break;
case( "checkbox" ): x.checked = !x.checked;
this.style.backgroundColor = ( x.checked ?
selectedColor : unselectedColor );
break;
case( "select" ) : // non standard
case( "select-multiple" ):
case( "select-one" ) : this.style.backgroundColor = (
x.selectedIndex ? selectedColor : unselectedColor );
break;
}
formWasChanged = true;
setTotal();
}
}

I've been thinking on your ideas as they were what I knew I needed to do but
couldn't think of how.

Thanks

Steffan

Sep 5 '07 #3
in article 11**********************@k79g2000hse.googlegroups. com, RobG at
rg***@iinet.net.au wrote on 9/5/07 3:22 AM:
On Sep 5, 1:01 pm, "Steffan A. Cline" <stef...@hldns.comwrote:
>I have a script that will cycle thru a form and add a handler to the row so
that if it is clicked it will check the checkbox within the row with
basically cb.checked = !cb.checked. This part works great except if you
click on the checkbox itself. It will also trigger the row. Am I missing an
obvious way of how to avoid that? Reason, like I was saying. Clicking on the
row toggles the checkbox but if the checkbox is unchecked and you check it,
it will instantly go back to unchecked making the appearance it was never
checked. Hence, it's always unchecked unless you hit the row. I need to come
up with something I can add into the code that looks at the checkbox somehow
to avoid this. It's as if the handler would need to see if it itself was
clicked or the control within it itself (the row).

1. Add a handler to the checkbox that cancels bubbling.

2. In the row handler, see if the target was the checkbox (or its
label) and don't toggle the checked property if it is.

I think 2. may be the better option.
I changed my control click handler per your suggestions.

myControl.onclick = function (e) {
e.cancelBubble = true;
...
}

This seems to work fine for me in safari and firefox. I haven't checked IE
yet, but is this what you were referring to? Are there any caveats to this?

Thanks,

Steffan

Sep 6 '07 #4

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

Similar topics

2
by: David Pautler | last post by:
I'm creating a web-based authoring tool where one form encompasses several sections for editing. I'd like each section to have its own reset button, so that use of that button affects only that...
2
by: drdeadpan | last post by:
Hi all, Is this legal ? SELECT a.col1,b.col2,c.col3 FROM tab1 a WITH (UPDLOCK) , tab2 b, tab3 c WHERE a.col1 = b.col1 and b.col2 = c.col1 WIll the above cause a UPDLOCK on tab1 and...
5
by: Patient Guy | last post by:
In my reading of the Strict and Transitional DTD for HTML 4.0, the table row (TR) elements are contained within table section elements: THEAD, TFOOT, and TBODY. The table section elements are...
3
by: Andrew Wrigley | last post by:
Hi I have what seems a corruption of an mdb that is not solved by the decompile command line trick. The problem appears when clicking on a subform control (check box) that has a event handler...
26
by: Daron | last post by:
How do I sort a table, from a form. I can't use SQL! WE have an Access application that is created by an outside vendor. The one form states: "Please make sure all records in table are sorted by...
2
by: George M. | last post by:
I'm working with the treeview control on an ASP.NET page (written in C#), and I have one built the looks something like: Root |_Category1 |_Site1 |_Report1 |_Report2 |_Site2 |_Report3...
3
by: Darin | last post by:
This is something that on the surface seems like it should be simple, but I can't think of a way to do this. I have a table that is a list of "jobs", which users create and use. It has a single...
13
by: Giggle Girl | last post by:
Hi there, I am having a problem with the behavior of Firefox, where lefthand column content is not resized properly after it is "collapsed" and then "re-expanded". An online demo is available...
2
by: SEFL | last post by:
Hi there, I've got a code sample below from a report from a computer database that I have built with a printer subtable, which in turn generates a printer subreport that I'm trying to put on its...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.