0

In a html table I have a checkboxes colums with the following markup:

<input type="checkbox" id="selection_2012-10-01-LIN-C" class="selections" name="selection_checkbox" disabled="disabled">
<input type="checkbox" checked="checked" id="selection_2012-10-01-ADE-C" class="selections" name="selection_checkbox">

On button click I need to validate if any of check boxes is selected, I m using the following code for that and getting false:

var selectedLots = $('input[name^="selection_checkbox"]').prop("checked");

Requriement is to get count of selected checkboxes or true, please guide me how select this.

Thanks

Toubi
  • 2,469
  • 10
  • 33
  • 49

2 Answers2

2

"Requriement is to get count of selected checkboxes"

var count = $('input[name^="selection_checkbox"]:checked').length;

"or true"

var anyChecked = $('input[name^="selection_checkbox"]:checked').length > 0;
// OR
var anyChecked = $('input[name^="selection_checkbox"]').is(':checked');

More information in the doco:

nnnnnn
  • 147,572
  • 30
  • 200
  • 241
1

You can use .is()

if(!$('input[name^="selection_checkbox"]').is(':checked')){
    //none of those are checked
}
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531