Simon
Simon

Reputation: 1169

counting checked checkboxes using jquery (keeps returning 0)

I would like to create an alert once too many check boxes have been checked.

Please see the setup here:

http://jsfiddle.net/wDbej/2/

At the moment - the alert keep returning 0 - rather than counting the checkboxes...

Any suggestions would be great thanks!

Upvotes: 0

Views: 83

Answers (2)

Matti Virkkunen
Matti Virkkunen

Reputation: 65126

You need to put the length calculation inside the event handler, otherwise it's just going to be calculated once in the start and be 0 constantly.

Upvotes: 1

Gazler
Gazler

Reputation: 84140

http://jsfiddle.net/wDbej/6/ - move your variable inside the click function. The way you had it initialized the variable, but didn't update the value on clicking the box.

Upvotes: 1

Related Questions