Skip to content

Instantly share code, notes, and snippets.

@southern-hu
Created April 20, 2013 02:06
Show Gist options
  • Save southern-hu/5424403 to your computer and use it in GitHub Desktop.
Save southern-hu/5424403 to your computer and use it in GitHub Desktop.
Get checkbox values (name field) http://jsfiddle.net/dvCmR/
<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" checked="checked" /> Option 2
<input id="chkbx_2" type="checkbox" name="c_n_2" checked="checked" /> Option 3
<input id="chkbx_3" type="checkbox" name="c_n_3" checked="checked" /> Option 4
</div>
<input type="button" id="clickme" value=""click me, now! />
$("clickme").click(function(e){
var selected = $("#checkboxes input:checked").map(function(i, el){
return el.name;}).get();
alert("selected = [" + selected + "]\nas string =\"" + selected.join(" ; ") + "\"");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment