gleddy
08-23-2004, 09:50 AM
heya,
this one has been killing me for a bit and I think it is time to stop and come back to it later...
here is the problem, I am trying to use 3 radio buttons (1,2 and 3) to change the bg colors of corresponding td cells (1,2, and 3). The color change is: red when button is checked, white when button is not.
but, I only want the td cell to be highlighted red when the button is checked. otherwise it should shut off. (or back to white.)
here is the code if anyone wants to have a look. I have it working so it turns the cells on, but they will not return back to white afterwards. Thanks for any help in advance...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function toggle() {
var form = document.forms[0];
for (var i=0; i < form.change.length; i++) {
if (form.change[0].checked) {
document.all.voila1.style.backgroundColor='red';
}
if (form.change[1].checked) {
document.all.voila2.style.backgroundColor='red';
}
if (form.change[2].checked) {
document.all.voila3.style.backgroundColor='red';
}
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="radio" name="change" value="voila1" onClick="toggle()" />11111111</label>
<input type="radio" name="change" value="voila2" onClick="toggle()" />22222222</label>
<input type="radio" name="change" value="voila3" onClick="toggle()" />33333333</label>
</form>
<table>
<tr>
<td name="voila1" id="voila1">11111111</td>
<td name="voila2" id="voila2">22222222</td>
<td name="voila3" id="voila3">33333333</td>
</tr>
</table>
</body>
</html>
thanks!
this one has been killing me for a bit and I think it is time to stop and come back to it later...
here is the problem, I am trying to use 3 radio buttons (1,2 and 3) to change the bg colors of corresponding td cells (1,2, and 3). The color change is: red when button is checked, white when button is not.
but, I only want the td cell to be highlighted red when the button is checked. otherwise it should shut off. (or back to white.)
here is the code if anyone wants to have a look. I have it working so it turns the cells on, but they will not return back to white afterwards. Thanks for any help in advance...
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<script type="text/javascript">
function toggle() {
var form = document.forms[0];
for (var i=0; i < form.change.length; i++) {
if (form.change[0].checked) {
document.all.voila1.style.backgroundColor='red';
}
if (form.change[1].checked) {
document.all.voila2.style.backgroundColor='red';
}
if (form.change[2].checked) {
document.all.voila3.style.backgroundColor='red';
}
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="">
<input type="radio" name="change" value="voila1" onClick="toggle()" />11111111</label>
<input type="radio" name="change" value="voila2" onClick="toggle()" />22222222</label>
<input type="radio" name="change" value="voila3" onClick="toggle()" />33333333</label>
</form>
<table>
<tr>
<td name="voila1" id="voila1">11111111</td>
<td name="voila2" id="voila2">22222222</td>
<td name="voila3" id="voila3">33333333</td>
</tr>
</table>
</body>
</html>
thanks!