faqts : Computers : Programming : Languages : JavaScript : Forms : Radio buttons

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

51 of 67 people (76%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How to make a check box enable or disable a group of radio buttons on a form?

May 29th, 2003 11:59
colleen stephan, Ade Taiwo,


<body>

<form name="form1">
  <input type=checkbox name=toggle onClick="disableRadioGroup(Option2, 
(this.value.length == 0))">
  <input type="radio" name="Option2" value="2a" >
  <input type="radio" name="Option2" value="2b" >
</form>

</body>

<script type="text/javascript">
<!--

function disableRadioGroup(radioGroup, disable)
{
  if(document.forms["form1"].elements["toggle"].checked){
  	for(var i=0; i < radioGroup.length; i++)
	  {
	    radioGroup[i].disabled = false
	  }
  }

else
{
  	for(var i=0; i < radioGroup.length; i++)
	  {
	    radioGroup[i].disabled = true
	  }
}
}


//-->
</script>