PDA

View Full Version : Checkboxes Question



mister5317
11-10-2006, 02:43 AM
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!

jscheuer1
11-10-2006, 06:33 AM
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?

mister5317
11-10-2006, 03:04 PM
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.

GITs
11-10-2006, 03:20 PM
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 :)

mister5317
11-10-2006, 03:36 PM
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.

jscheuer1
11-10-2006, 05:19 PM
Replace:


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:


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;
}
};

mister5317
11-10-2006, 05:24 PM
Perfect! :) Thank you so much!