aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes counting checked checkboxes in a table Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "counting checked checkboxes in a table" Watch "counting checked checkboxes in a table" New topic
Author

counting checked checkboxes in a table

J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 914
    
  13

I have a table displaying multiple rows of data, each row contains a checkbox. I know how to bind to the click event with jQuery, but what I'm struggling with is how to count the number of checkboxes that are checked. If two are already checked and the user tries to check a third, I need to popup a dialog telling them that only two records can be selected and that they must uncheck one before they can check another. I know how to use .dialog, so we don't need to get into the details of that. I just need a little push on iterating over all the checkboxes and determining if they are checked or not.

Be gentle with me, Bear, I'm only on chapter 2 of your book. Javascript and jQuery are very new to me.

Thanks!


"The good news about computers is that they do what you tell them to do. The bad news is that they do what you tell them to do." -- Ted Nelson
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65



(Of course replace myForm with the id of your form element.)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
J. Kevin Robbins
Bartender

Joined: Dec 16, 2010
Posts: 914
    
  13

Nice. A single line of code. jQuery is amazing.

Thank you, very much. And thanks for jqia.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60997
    
  65

 
wood burning stoves
 
subject: counting checked checkboxes in a table