Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    checkbox groups in single form with select all checkbox

    hi,

    This is the code I have so far. I would like to make the 'Select all' checkboxes only select all of the checkboxes in its group. And then deselect when it's unchecked.

    I've had a good look around and couldn't find how to make this work with groups on the page.

    Would be great if anyone knows of any script here that might be able to help.

    thanks,

    jo

    This is an example of how I need it to work:
    http://www.textit.com.au/checkboxform.cfm

    and this is the code:

    PHP Code:
    <script>
    function 
    toggle(theDiv) {
        var 
    elem document.getElementById(theDiv);
        
    elem.style.display = (elem.style.display == "none")?"":"none";
    }
    //-->
    </script>


    <form action="checkboxForm.cfm" method="post">
    <!---display group name--->
    <a href="#" class="bodyItemSmall" onclick="toggle('group1');return false;">Group 1</a><br>

    <div id="group1" style="display: none;"> 
    <!---get the group here--->
      <table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#CCCCCC">
        <tr>
        <td><input type="checkbox" name="selectAll" value="checkbox"> Select all
    </td>
      </tr>
    </table>
    <!---display the group here--->
    <input type="checkbox" name="contactID" value="1">firstName lastName<br>
    <input type="checkbox" name="contactID" value="2">firstName lastName<br>
    <input type="checkbox" name="contactID" value="3">firstName lastName<br>
    </div>

    <!---display group name--->
    <a href="#" class="bodyItemSmall" onclick="toggle('group2');return false;">Group 2</a>

    <div id="group2" style="display: none;"> 
    <!---get the group here--->
      <table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#CCCCCC">
        <tr>
        <td><input type="checkbox" name="selectAll" value="checkbox"> Select all
    </td>
      </tr>
    </table>
    <!---display the group here--->
    <input type="checkbox" name="contactID" value="1">firstName lastName<br>
    <input type="checkbox" name="contactID" value="6">firstName lastName<br>
    <input type="checkbox" name="contactID" value="8">firstName lastName<br>
    </div>
    </form> 

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,529
    Thanks
    3
    Thanked 511 Times in 498 Posts
    while I look at your code see

    http://www.vicsjavascripts.org.uk/Fo...pendium.htm#f5



    Code:
    ...........
    function CkAllNone(obj,id){
     var tbs=document.getElementById(id).getElementsByTagName('INPUT');
     for (var zxc0=0;zxc0<tbs.length;zxc0++){
      tbs[zxc0].checked=obj.checked;
     }
    }
    //-->
    </script>
    
    
    <form action="checkboxForm.cfm" method="post">
    <!---display group name--->
    <a href="#" class="bodyItemSmall" onclick="toggle('group1');return false;">Group 1</a><br>
    
    <div id="group1" style="display: none;">
    <!---get the group here--->
      <table width="100%" border="0" cellspacing="0" cellpadding="2" bgcolor="#CCCCCC">
        <tr>
        <td><input type="checkbox" name="selectAll" value="checkbox" onclick="CkAllNone(this,'group1');" > Select all
    </td>
      </tr>
    </table>
    <!---display the group here--->
    <input type="checkbox" name="contactID" value="1">firstName lastName<br>
    <input type="checkbox" name="contactID" value="2">firstName lastName<br>
    <input type="checkbox" name="contactID" value="3">firstName lastName<br>
    </div>
    ...............
    Last edited by vwphillips; 12-24-2005 at 12:10 PM.

  • #3
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    hi Vic,

    lol. I got the reply-to-post email and was in such a rush to check out how to do this I just clicked on the link in the email and went to your site... installed the script... got it sorted and then came to reply and found the rest of your post!

    Thank you so much for your response. I actually prefer the non toggling text version in your post and it works fabulously... thank you, thank you, thank you!

    jo

  • #4
    New Coder
    Join Date
    Feb 2003
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi Vic,

    I might push my luck a bit and ask you how I can run a statement to open each div (on my other script) if preferred.

    Something like this I was hoping for:
    PHP Code:
    <cfif group1preferenceOpen is "N">
    <
    div id="group1" style="display: none;">
    <
    cfelse>
    <
    div id="group1" style="display:.....
    </cfif> 
    Or should it happen somewhere else?

    All the new code is on this page:
    http://www.textit.com.au/checkboxForm.cfm

    Thank you once again,

    jo


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •