Using jquery to change checkbox status

Posted by Jeff on Stack Overflow See other posts from Stack Overflow or by Jeff
Published on 2010-05-24T16:51:57Z Indexed on 2010/05/24 17:01 UTC
Read the original article Hit count: 168

Filed under:
|
|
|

Hi everyone!

I have a list of items that have checkboxes associated with them, and the items are beneath a list header, which also has a checkbox(for db purposes only) which is actually hidden from view. I need to make it so that if any of the checkboxes beneath the header is checked, then the header checkbox is checked as well. BUT I also need to make it so that if all of the checkboxes are unchecked, then the header one is unchecked...how hard is this going to be?

This is how I have it setup now:

if($('.childCheckBox').is(":checked")){
$('#parentBox').attr('checked', true);
}

Now I am thinking that if I were to do something where I add an else if clause:

else if($('.proBox2').is(not)(":checked"){
alert("uncheck parent");
}

But I don't know the correct syntax for is-not, or isn't, or even if there is anything that will do that. Are there any thoughts out there? I need the box to check if one is selected and uncheck if none are selected. Thanks!!

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about html