cophi
asked on
Javascript Disable Radio Buttons
I am trying to disable a group of Radio Buttons in IE 7.
This is what the html looks like.
<TD style="PADDING-RIGHT: 15px"><INPUT id=123 onclick="" type=radio value=123 name=mode><LABEL for=123>Blue</LABEL></TD>
<TD style="PADDING-RIGHT: 15px"><INPUT id=321 onclick="" type=radio value=321 name=mode><LABEL for=321>Green</LABEL></TD>
In my javascript I have tried....
for (var b = 0; b < mode.length; b++)
mode[b].disabled = true;
... that did not work at all
I then tried
mode.disabled = true;
.... this at least disabled the first radio button.
This is what the html looks like.
<TD style="PADDING-RIGHT: 15px"><INPUT id=123 onclick="" type=radio value=123 name=mode><LABEL for=123>Blue</LABEL></TD>
<TD style="PADDING-RIGHT: 15px"><INPUT id=321 onclick="" type=radio value=321 name=mode><LABEL for=321>Green</LABEL></TD>
In my javascript I have tried....
for (var b = 0; b < mode.length; b++)
mode[b].disabled = true;
... that did not work at all
I then tried
mode.disabled = true;
.... this at least disabled the first radio button.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
btw - obviously the javascript function needs to go within <script></script> tags (in the <head> section).
<html>
<head>
<title>Enable Buttons</title>
<script language='JavaScript' type='text/javascript'>
function Enable( name, val ) {
var buttons = document.getElementsByName ( name );
for ( var i = 0; i < buttons.length; i++ ) {
buttons[ i ].disabled = val;
}
}
</script>
</head>
<body>
<table border='1'>
<tbody>
<tr>
<td><input id='r123' onclick='' type='radio' value='123' name='mode'><label for='r123'>Blue</label></t d>
</tr>
<tr>
<td><input id='r321' onclick='' type='radio' value='321' name='mode'><label for='r321'>Green</label></ td>
</tr>
</tbody>
</table>
<form id='myForm' action=''>
<input type="button" value='Enable' onclick='Enable("mode",fal se)' />
<input type="button" value='Disable' onclick='Enable("mode",tru e)'/>
</form>
</body>
</html>
<head>
<title>Enable Buttons</title>
<script language='JavaScript' type='text/javascript'>
function Enable( name, val ) {
var buttons = document.getElementsByName
for ( var i = 0; i < buttons.length; i++ ) {
buttons[ i ].disabled = val;
}
}
</script>
</head>
<body>
<table border='1'>
<tbody>
<tr>
<td><input id='r123' onclick='' type='radio' value='123' name='mode'><label for='r123'>Blue</label></t
</tr>
<tr>
<td><input id='r321' onclick='' type='radio' value='321' name='mode'><label for='r321'>Green</label></
</tr>
</tbody>
</table>
<form id='myForm' action=''>
<input type="button" value='Enable' onclick='Enable("mode",fal
<input type="button" value='Disable' onclick='Enable("mode",tru
</form>
</body>
</html>
one moment...