Forum Moderators: open

Message Too Old, No Replies

how do i change the css style of a label when it's radio button is che

radio button and css styles.

         

LouLou

1:26 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



Hello,

i was wondering if anyone could help me out here.

I have two radio buttons.

One button is marked as checked.

What i want to do is change the CSS style of the label text when either of the buttons is selected.

I have a feeling this will involve javascript.

If anyone could offer their insight i would be gratefull.

Thanks,

Lou

RonPK

2:46 pm on Jul 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, try this:

<script type="text/javascript"> 
<!--
function styleToggle(b) {
for (var i = 0; i< b.form.length; i++) {
if (b.form[i].name == b.name) {
b.form[i].parentNode.style.backgroundColor = b.form[i].checked? 'red' : '';
}
}
}
// -->
</script>
<form>
<label for="but01">
<input type="radio" name="somename" id="but01" value="ho" onclick="styleToggle(this)">
label text here
</label><br>
<label for="but02">
<input type="radio" name="somename" id="but02" value="hi" onclick="styleToggle(this)">
label text here
</label>
</form>

LouLou

3:04 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



Hi there,

that seems to work fine when i toggle the fontWeight!

Many Thanks,

Lou