Click to See Complete Forum and Search --> : Disable radios with checkbox?


morty
10-17-2003, 10:54 AM
Where is my mistake? I want to set disabled=false for three radiobuttons by clicking in a checkbox and diable them when I uncheck the Checkbox. My script is somehow not working...? I would be thankfull for a hint!

<html>
<head>
<script type="text/javascript">
function changer()
if(this.form2.activator.checked){
this.form2.decision[0].disabled=false;
this.form2.decision[1].disabled=false;
this.form2.decision[2].disabled=false;
}else{
{
this.form2.decision[0].disabled=true;
this.form2.decision[1].disabled=true;
this.form2.decision[2].disabled=true;
}
</script>
</head>
<body>
<table width="400" border="1" cellpadding="0" cellspacing="0">
<form name="form2" method="post" action="">
<tr>
<td colspan="3"> <input type="checkbox" name="activator" value="checkbox" onClick="changer()">
</tr>
<tr>
<td width="100"><input type="radio" name="decision" value="first" disabled="true"> </td>
<td width="100"><input type="radio" name="decision" value="second" disabled="true"></td>
<td width="100"><input type="radio" name="decision" value="third" disabled="true"></td>
</tr>
</form>
</table>
</body>
</html>

Phil Karras
10-17-2003, 11:35 AM
Just a small modification to your function seems to make it all work here:

function changer() { // pk added brace
if(this.form2.activator.checked){
this.form2.decision[0].disabled=false;
this.form2.decision[1].disabled=false;
this.form2.decision[2].disabled=false;
}
else{
//{ pk removed brace
this.form2.decision[0].disabled=true;
this.form2.decision[1].disabled=true;
this.form2.decision[2].disabled=true;
}
} // pk added closing brace, for the function

All functions MUST be enclosed in braces.

morty
10-17-2003, 12:15 PM
Thanks pk, now it works perfectly!!
I'm happy...