views:

15

answers:

1

I have this code that will check the top level checkbox if
the checkboxes underneath it are selected. What I also want to do
is to unselect the top level check box, if there are no checkboxes selected underneath it. How can I modify this. Thanks

if(this.parentElement == pg.thePart) {

            var terminate = false;
            var counter = 0;
        if(n.className == "myClass") {

                z = n.nextSibling;


                while(z.id == "row" && z.className != "myClass" && !terminate) {
                    z.all[0].checked = 0;
                    z.style.backgroundColor = z.className == "w" ? "ffffff" : "ffffcc";
                    counter++;
                    if(counter > 1000) terminate = true;
                    z = z.nextSibling;
                }
            } else {
                z = n;
                while (z.className != "myClass" && !terminate) {
                    z = z.previousSibling;
                    counter++;
                    if(counter > 1000) terminate = true;
                }
                if(counter > 0 && counter <= 1000) {

                    z.all[0].checked = 1;
                    z.style.backgroundColor = "bad3fc";
                }


            }


        }
+1  A: 

You can test the ones below it, if they are not checked then use:

checkbox.checked = false;
John