User
User

Reputation: 1662

get the check box count using javascript

I have three check box and one button in a form.name like as selectall , city ,state.if I check selectall button the remaining city and state also getting selected.its work fine.I need to get count of selected check boxes except that selectall . Which means if I select either city or state I need count as 1.if I select city and state I need count as 2.I don't want to count selectall button count???

In my case if I check the selectall button the remaining two check boxes also checked as per requirements.but I need to count the city and state alone except selectall .how to do this???

Upvotes: 0

Views: 103

Answers (2)

RGS
RGS

Reputation: 5211

Try this:

$('input[type="checkbox"]').change(function(){
  var count = $('input[type="checkbox"]:not("#chkselectall"):checked').length;
});

Demo:

http://jsfiddle.net/Lbs39h97/

Upvotes: 1

nnnnnn
nnnnnn

Reputation: 150020

Well with jQuery it's easy. Assuming you can give the "select all" checkbox the "selectall":

var count = $("#YourFormID input[type='checkbox']:checked").not("#selectall").length;

Demo: http://jsfiddle.net/tkevs5q6/

Upvotes: 1

Related Questions