I have got id's of all the row which have check box in a variable.
var allIds = jQuery("#progAccessSearchResults").jqGrid("getDataIDs");
Now I have to iterate over this and get id's of only checked check boxes. I tried following code to get checked checkbox id.
var boxes = $(":checkbox:checked");
But it is not working. Help me out..!! I am new to javascript n jquery. So pls don't mind if it is a silly problem..!!
You can use .map to find all IDs of checked checkboxes, using your existing selector:
HTML:
<input type="checkbox" id="cb1" />
<input type="checkbox" id="cb2" />
<input type="checkbox" id="cb3" checked="checked" />
<input type="checkbox" id="cb4" />
<input type="checkbox" id="cb5" checked="checked" />
Javascript:
var checkedIds = $(":checkbox:checked").map(function() {
return this.id;
}).get();
Returns: [ "cb3", "cb5" ]
Here is a fiddle for the above code.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With