Clicking anywhere on report row

U

usenet

I have a HTML table with onmouseover/onmouseout event handlers to
change the bgcolor of the report row as the mouse moves over it.

The row also has a radio button on it.

Is there a way to click anywhere on the row and have the radiobutton be
clicked?

By attaching a onClick on the TR and having it bubble up (down?) to the
radio element or something?

Thanks
 
U

usenet

OK got it working

Added a onClick event handler to the TR tag

<tr onClick="ClickRadio(this);">

Do I need to worry about the onClick event bubbling up to higher
elements? Do I need to do the cancelPropagation and stuff?

<script type="text/javascript">
function ClickRadio(p_tr)
{
var l_element;
for( var ii = 0; ii < p_tr.childNodes.length; ii++ ) {
if (p_tr.childNodes[ii].tagName=="TD") {
for (var j=0; j< p_tr.childNodes[ii].childNodes.length;j++)
{
l_element=p_tr.childNodes[ii].childNodes[j];
if (l_element.tagName=='INPUT' &&
l_element.type=="radio") {
l_element.checked=true;
}
}
}
}
}
</script>

Works like a charm.

Hope this helps someone.
 
R

RobG

OK got it working

Added a onClick event handler to the TR tag

<tr onClick="ClickRadio(this);">

Do I need to worry about the onClick event bubbling up to higher
elements? Do I need to do the cancelPropagation and stuff?

Only if you want to prevent a click on your row from firing some other
onclick higher up the DOM.
<script type="text/javascript">
function ClickRadio(p_tr)
{
var l_element;
for( var ii = 0; ii < p_tr.childNodes.length; ii++ ) {
if (p_tr.childNodes[ii].tagName=="TD") {
for (var j=0; j< p_tr.childNodes[ii].childNodes.length;j++)
{
l_element=p_tr.childNodes[ii].childNodes[j];
if (l_element.tagName=='INPUT' &&
l_element.type=="radio") {
l_element.checked=true;
}

If you want to just check the radio button in the row, and presuming
p_tr is a reference to a row element, try:

var inputs = p_tr.getElementsByTagName('input');
var el, i = inputs.length;
while (i--){
el = inputs
if ( el.type = 'radio' ){
el.checked = true;
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top