Jump to content

Check boxes script help


Darkmatter5

Recommended Posts

Do you mean like

 

(checkbox) Yes I would like to subscribe to all of these

 

    (checkbox) magazine 1

    (checkbox) magazine 2

    (checkbox) magazine 3

    (checkbox) magazine 4

 

and when they check Yes I would like to subscribe to all of these then it will check/uncheck all of those?

 

To do that you use this code

 

<script type="text/javascript">
function radio()
{
      if(document.form1.radio.checked == false)
      {
            document.form1.radio.checked = true;
      }
      else (document.form1.radio.checked == true)
      {
            document.form1.radio.checked = false;
      }
}
</script>

 

Link to comment
Share on other sites

He asked to have all the other field unchecked if the particular field was checked. This will do that, as well as disable the fields when unchecked.

 

<html>
<head>
<script type="text/javascript">

function uncheckAll(uncheckAll_switch)
{
    //Uncheck all boxes if option checked
    if (uncheckAll_switch)
    {
        document.getElementById('check1').checked = false;
        document.getElementById('check2').checked = false;
        document.getElementById('check3').checked = false;
        document.getElementById('check4').checked = false;
    }

    //Disable/Enable all the checkboxes
    document.getElementById('check1').disabled = uncheckAll_switch;
    document.getElementById('check2').disabled = uncheckAll_switch;
    document.getElementById('check3').disabled = uncheckAll_switch;
    document.getElementById('check4').disabled = uncheckAll_switch;

    return;
}

</script>
</head>
<body>

<input type="checkbox" name="clear_all" id="clear_all" onclick="uncheckAll(this.checked);">
Check here to uncheck all other boxes
<br><br>
<input type="checkbox" name="check1" id="check1"> Checkbox 1<br>
<input type="checkbox" name="check2" id="check2"> Checkbox 2<br>
<input type="checkbox" name="check3" id="check3"> Checkbox 3<br>
<input type="checkbox" name="check4" id="check4"> Checkbox 4<br>

</body>
</html>

Link to comment
Share on other sites

Oh well thats why I asked if thats what he was asking before posting my code.

Actually I misread your response. Your code does uncheck the "child" field when the "parent" is checked. But, it also checks the "child" when the "parent" is unchecked. Not sure if that was what he wanted. But, then again, not enough specifics were given.

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.