Jump to content

enable/disabe button group


NickG21

Recommended Posts

hey everyone im looking to disable a group of radio buttons and a group of checkboxes if one checkbox is checked at the beginning of the site.  i have put up a few posts so i apologize for any repitition just trying to see if there is anyone else on here who could give me a little insight? right now here is the function i have to do the work but it doesn't work.  also, i am extremely new at this so any help is much appreciated
thank you

[CODE]<!--
function DisableRadioGroup(radioGroup, disable)
{
if(document.forms["form1"].elements["OwnersManual"].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
  }
}
}
//-->[/CODE]
Link to comment
https://forums.phpfreaks.com/topic/32211-enabledisabe-button-group/
Share on other sites

your if statement seems to be incorrect, I am not all that good with javascript but you could try this
[code]
<!--
function DisableRadioGroup(radioGroup, disable)
{
if(document.getElementById("OwnersManual").checked == true){
  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
  }
}
}
//-->
[/code]

and I take it this function is called in the onclick event of the checkbox??

[code]
<INPUT TYPE=checkbox  ID="OwnersManual" onclick="DisableRadioGroup(radioGroup, disable)">
[/code]
that looks better than mine for sure and with a few minor adjustments worked perfectly, one more thing, is there anyway to implement a group of checkboxes as well or do i have to go through and individually make them disable after the box is checked?
you'll probably have to scan through the form and disable checkboxes one by one. Here's an example I made where any checkbox who's "name" starts with "somebox" would be disabled.

[code]
f = document.forms["form1"];
for (i = 0 ; i < f.elements.length; i++) {
if ((f.elements[i].type == "checkbox") && (f.elements[i].name.substring(0,7) == "somebox"))
f.elements[i].disabled=true;
}
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.