views:

94

answers:

1

I have 10 checkboxes that are scattered throughout a page and if any one of them is checked, then a div needs to have it's display set to block. However if they are all unchecked then the div is set back to display:none. They are in different parts of the page and I am having problems figuring out how to detect the check.

Thanks,

-Seth

EDIT

Sorry their are checkboxes that have nothing to do with showing this div or not, so simply doing the blanket input:checkbox in jquery won't work exactly.

+4  A: 
$('input[type=checkbox].chkbxgroup').change(function(){
   if($('input[type=checkbox].chkbxgroup').is(':checked')({
       $('div#hiddenDiv').show();
   }
   else{
       $('div#hiddenDiv').hide();
   }
});

I think that should do it, assuming the is(':checked') part will return true if 1 or more of the elements in that set are checked.

[edit re: comment] add a class to all the check boxes that you want to be affected by this. updated my code thusly [/edit]

idrumgood
Yeah sorry I should have noted that there are other checkboxes on the page that shouldn't have any effect on if the div is shown or not (in other words they don't deal with that div whatsoever)
Seth Duncan
+1 - your update to add the selector filter looks much better
Scott Ivey
+1 Thank you very much very good response time and even better answer.
Seth Duncan