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
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]
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.