Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Apply CSS style for table row if radio button is clicked

Reply
Thread Tools

Apply CSS style for table row if radio button is clicked

 
 
iwasjoeking
Guest
Posts: n/a
 
      06-06-2007
Hi all,

I am trying to make it so that the style "RowSelected" (embedded
below) is applied to the table row from which the radio button is
selected, and then removed when a different radio button is clicked.

Right now, the below code kinda works. The javascript was copied from
an example on a website from which I forgot the URL. It only applies
the style properties to the label text, and not to the row.

If anyone can help, I would really appreciate it. Thanks!

Here is what I have so far:

* * * * * * * * * * * * * * * * * * * * * * * * * * *
<html>

<style type="text/css">
<!--
..RowSelected {
color: blue;
font-weight: bold;
}
-->
</style>
</head>
<body>

<script type="text/javascript">
function styleToggle(rdoVar) {
for ( var i = 0; i < rdoVar.form.length; i++){

if (rdoVar.form[i].name == rdoVar.name) {
rdoVar.form[i].parentNode.style.color = rdoVar.form[i].checked?
'red' : '';
rdoVar.form[i].parentNode.style.fontWeight =
rdoVar.form[i].checked? 'bold' : '';
}

}
}
</script>

<form>
<table width="100%" border="1">
<tr>
<td><input type="radio" name="InterestingItem" id="afdsa"
value="Item 01" onClick="styleToggle(this)" />
Item 01</td>
<td>Description 01</td>
</tr>
<tr>
<td><input type="radio" name="InterestingItem" id="afdasfd"
value="Item 02" onClick="styleToggle(this)" />
Item 02</td>
<td>Description 03</td>
</tr>
<tr>
<td><input type="radio" name="InterestingItem" id="afadf"
value="Item 03" onClick="styleToggle(this)" />
Item 03</td>
<td>Description 03</td>
</tr>
</table>
</form>

</body>
</html>

 
Reply With Quote
 
 
 
 
chatterman
Guest
Posts: n/a
 
      06-06-2007
styleToggle( this)

'this' refers to the input object

the parentNode of the input object is the <td> containing the <input>

the parentNode of the <td> is the <tr> object

so

function styleToggle(rdoVar){

var tdNode= rdoVar.parentNode;
var trNode= tdNode.parentNode;

if( rdoVar.checked ){
trNode.style.color = "red";
trNode.style.fontWeight = "bold";
}else{
// etc..
}
}


 
Reply With Quote
 
 
 
 
iwasjoeking
Guest
Posts: n/a
 
      06-07-2007
That did the trick.

Thanks Chatterman!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Spring java Controller get correct data from button when "apply"button is clicked but not pressing the <Enter> key albert kao Java 1 04-10-2010 02:54 AM
Validation Problems, Require text box if a radio button is clicked djjohnst ASP .Net 0 06-06-2007 03:28 PM
Radio button List problem: How to find value of Radio button list's Selected Item using javascript?? Hiten ASP .Net Web Controls 1 05-26-2004 10:32 AM
Newbie question about CSS - can you apply a style to an entire table or only to a <TD> cell Shiperton Henethe HTML 5 09-19-2003 01:58 AM
Radio Button List ---> onclick event. You can never know when the user clicked? Leeor Geva ASP .Net 1 08-30-2003 01:09 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57