I want to get a list of names of checkboxes that are selected in a div with certain id. How would I do that using jQuery?
E.g., for this div I want to get array ["c_n_0"; "c_n_3"] or a string "c_n_0;c_n_3"
<div id="checkboxes">
<input id="chkbx_0" type="checkbox" name="c_n_0" checked="checked" />Option 1
<input id="chkbx_1" type="checkbox" name="c_n_1" />Option 2
<input id="chkbx_2" type="checkbox" name="c_n_2" />Option 3
<input id="chkbx_3" type="checkbox" name="c_n_3" checked="checked" />Option 4
</div>
This works for me.
will give you an array of the elements themselves. If you just specifically need the names:
Would this do?
Combination of two previous answers:
I needed the count of all checkboxes which are checked. Instead of writing a loop i did this
Compare it with the total number of checkboxes to see if they are equal. Hope it will help someone
You could also give them all the same name so they are an array, but give them different values:
You can then get only the value of only the ticked ones using map: