Forum Moderators: open
Instead of adding onchange event to each of them, can I simply add an event to the form so that whenever there is an onchange event on radio buttons, I can call JS to bold corresponding radio button's text (if checked) or un-bold the text (if unchecked).
Thanks.
<td><input type="radio" name="item178" value="3" >Lots of help</td>
<td><input type="radio" name="item178" value="4" >Extremely helpful</td>
...
<td><input type="radio" name="item179" value="3" >Lots of help</td>
<td><input type="radio" name="item179" value="4" >Extremely helpful</td>
When people click radio buttons, I want to bold selected button's text (Lots of Help or Extremely Helpful) or un-bold them.
Thanks.
does this help...
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript"><style type="text/css">
label {
display:block;
margin:4px 0;
}
.bold {
font-weight:bold;
}
</style><script type="text/javascript">
if(window.addEventListener){
window.addEventListener('load',boldLabels,false);
}
else {
if(window.attachEvent){
window.attachEvent('onload',boldLabels);
}
}function boldLabels(){
inps=document.forms[0].getElementsByTagName('input');
for(c=0;c<inps.length;c++) {
if(inps[c].type=='radio'){
inps[c].checked=false;
inps[c].onclick=function() {
for(c=0;c<inps.length;c++) {
if(inps[c].name==this.name){
inps[c].parentNode.className='';
}
}
this.parentNode.className='bold';
}
}
}
}
</script></head>
<body><form action="#">
<div>
<label><input type="radio" name="item176"> Lots of help</label>
<label><input type="radio" name="item176"> Extremely helpful</label><label><input type="radio" name="item177"> Lots of help</label>
<label><input type="radio" name="item177"> Extremely helpful</label><label><input type="radio" name="item178"> Lots of help</label>
<label><input type="radio" name="item178"> Extremely helpful</label><label><input type="radio" name="item179"> Lots of help</label>
<label><input type="radio" name="item179"> Extremely helpful</label>
</div>
</form></body>
</html>
birdbrain
No problem, you're very welcome. ;)