Use either a commonality in the naming scheme (either of the 'name' or 'id' attributes) or use DOM methods on a common parent node to iterate over all of the checkboxes. Stop at the first one you find that is checked. If the loop terminates and you never found one, your condition wasn't met.
var hasChecked = $('input[type=checkbox]:checked').length > 0;
Last edited by Derokorian; 02-14-2013 at 02:59 PM.
Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail I'd rather be a comma, then a full stop. User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning
The DOM/XPath version is about three times longer...
... unless, of course, your website has no other use of jQuery, in which case I would say the DOM/XPath version (or even the simplistic approach I proposed above) is several orders of magnitudes smaller when compared with (the above jQuery statement + the jQuery library).
@NZ_Kiwis: Moral of the story: There's more than one way to skin a mongoose. (Actually, there are three...)
I agree, if this is the only thing you use jQuery on its not necessary to include the whole library for something like simple. However, personally I have lots of jQuery all throughout sites I've worked on, so I'm just used to doing it all in jQuery.
Sadly, nobody codes for anyone on this forum. People taste your dishes and tell you what is missing, but they don't cook for you. ~anoopmail I'd rather be a comma, then a full stop. User Authentication in PHP with MySQLi - Don't forget to mark threads resolved - MySQL(i) warning
Bookmarks