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

Apply CSS style for table row if radio button is clicked

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>

Jun 6 '07 #1
2 5644
styleToggle( this)

'this' refers to the input object

the parentNode of the input object is the <tdcontaining the <input>

the parentNode of the <tdis the <trobject

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..
}
}
Jun 6 '07 #2
That did the trick.

Thanks Chatterman!

Jun 7 '07 #3

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

Similar topics

2
by: Tonya | last post by:
Hi, i wanted to know how i could resolve the following error message: An unhandled exception of type 'System.ArgumentException' occurred in system.dll Additional information: The data grid...
4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
5
by: ste.paoletti | last post by:
I have a problem with css I have a this xhtml code: <span> <span> <span/> <input type="radio"/> .... <span/> <input type="button" onclick ="var s=document.createElement('span');...
16
by: Stuart | last post by:
I have a page where I utilise the left and right cursor keys to change an image, also on this page is a groups of radio buttons, unfortunately when a radio button is clicked the focus for the...
8
by: stefano | last post by:
HI, I have aproblem with XHTML radio button. <form name=" form"> <input name="radio" type="radio" onclick="return false" /> <input name="radio" type="radio" onclick="return false" /> <input...
1
by: eureka | last post by:
Hi folks, I am working on a webapplication using Jsp and JS. On my main Jsp(Jsp1) I have a table which is created dynamically inside a <divand contains all the backend-table's records as rows,...
5
by: g | last post by:
Hi Guys.. i know this might sound really really simple, but I'm kinda stuck..I have this form..which has a table (created from stored procedure values)..once the table is populated..i have some...
0
by: jehugaleahsa | last post by:
Hello: I have radio buttons bound to boolean properties in a business object. private void bindRadioButton(RadioButton button, string propertyName) { Binding binding =...
1
by: ramel | last post by:
Hi all, I have a problem related to javascript , ajax and jsp. Please see this url http://xil.co.in/print_screen_2.JPG. I am working on this form. There are some buttons (like submit ,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...

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.