Getting Amount Of Checkboxes Checked By Name
I'm trying to find out how many checkboxes have been checked but am having some trouble.. My checkboxes are all named delete[]. var count = ($('#form_store_setup input[name=delete]
Solution 1:
You need to escape the square brackets. Try this:
var count = $('#form_store_setup input[name=delete\\[\\]]:checked').length;
Or put the attribute value in quotes:
var count = $('#form_store_setup input[name="delete[]"]:checked').length;
Solution 2:
Simply wrap delete[] in double quotes in your second example like this:
var count = ($('#form_store_setup input[name="delete[]"]:checked').length);
Solution 3:
Assuming you do not have any other named items, that begin with delete
, you can use the "starts with" matching:
var count = ($('#form_store_setup input[name^=delete]:checked').length);
Solution 4:
This should do the trick. Try adding single quotes around your input name. Also you can call .size() instead of .length for the same effect.
var count = ($('#form_store_setup input[name='delete[]']:checked').length);
See this document for reference regarding the size() function (http://api.jquery.com/size/)
Post a Comment for "Getting Amount Of Checkboxes Checked By Name"