Created
April 20, 2013 02:06
-
-
Save southern-hu/5424403 to your computer and use it in GitHub Desktop.
Get checkbox values (name field)
http://jsfiddle.net/dvCmR/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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! /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$("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