Results 1 to 7 of 7

Thread: Checkboxes Question

  1. #1
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Checkboxes Question

    I recently found jscheuer1 check/uncheck script at:
    http://home.comcast.net/~jscheuer1/side/table_check.htm

    This script would work perfect for me, but I need a small little tweak. Instead of if all of the checkboxes are checked, check the 'check all' checkbox...I need the script to check if any of the child checkboxes are checked, and if so then check the 'check all' checkbox. This is very similar to a checkbox tree. Also, if none of the child checkboxes are checked, the 'check all' checkbox should not be checked either.

    Can someone please help me? Thank you!

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    You left out what you would want to have happen if the user checks the 'check all' box or if you want it to be read-only. Also, just out of curiosity, since it obviously is no longer a 'check all' box, what would it be called?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Sorry, I forgot about that. It will actually be hidden, the user will never see the checkbox, but 'check all' checkbox will be used in a PHP script.

    So the short answer is, nothing.

    Thanks again.

  4. #4
    Join Date
    Nov 2006
    Location
    UK
    Posts
    23
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    instead of this, have a javascript function count up the amount of checked boxes, if it meets the amount on the page, the hidden fields value would be set to true, as the "Check All" box is going to be hidden, just have it as an input with type "hidden" and makes the value true, then you can read it off as if it were a checkbox anyway. then, as you uncheck the boxes, decrease the number... should be simple enough to employ

  5. #5
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I want to use jscheuer1 scripts because there is going to be groups of checkboxes like in his example.

    I have tried the count method but it didnt work the way i wanted it to work. jscheuer1's script is perfect for what i need. Thanks for the suggestion though.

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Replace:

    Code:
    boxes[i_tem][0].onclick=function(){
    if(!this.checked){
    for (var i_tem = 0; i_tem < boxes.length; i_tem++)
    if(boxes[i_tem][0].col==this.col){
    boxes[i_tem][0].checked=0;
    return;
    }
    }
    else{
    var b=[];
    for (var i_tem = 0; i_tem < boxes.length; i_tem++)
    if(boxes[i_tem][0].col==this.col)
    b[b.length]=boxes[i_tem][0];
    if (!b[0].checked)
    for (i_tem = 1; i_tem < b.length; i_tem++)
    if(!b[i_tem].checked)
    return;
    b[0].checked=1;
    }
    };
    with:

    Code:
    boxes[i_tem][0].onclick=function(){
    if(this.checked){
    for (var i_tem = 0; i_tem < boxes.length; i_tem++)
    if(boxes[i_tem][0].col==this.col){
    boxes[i_tem][0].checked=1;
    return;
    }
    }
    else{
    var b=[];
    for (var i_tem = 0; i_tem < boxes.length; i_tem++)
    if(boxes[i_tem][0].col==this.col)
    b[b.length]=boxes[i_tem][0];
    if (b[0].checked)
    for (i_tem = 1; i_tem < b.length; i_tem++)
    if(b[i_tem].checked)
    return;
    b[0].checked=0;
    }
    };
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  7. #7
    Join Date
    Nov 2006
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Perfect! Thank you so much!

Bookmarks

Posting Permissions

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