views:

117

answers:

4

Hi how can i calculate the number of checkboxes that a user has checked using jquery?

what i want to do is limiting the number of checking for checkboxes in a form to 10 for example and when a user exceeds this range display a warning message.

A: 

try this:

Method 1:

alert($('#checkbox_id_here :checked').size());

Method 2:

alert($('input[name=checkbox_name]').attr('checked'));

Method: 3

alert($(":checkbox:checked").length;);
Sarfraz
+1  A: 

Have a look here

jquery Selectors/checked

astander
A: 

This should work:

alert($("input:checkbox:checked").length);
James Wiseman