Created
September 20, 2013 18:40
-
-
Save ursuleacv/6641938 to your computer and use it in GitHub Desktop.
Getting all selected checkboxes in an array
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
| <input type="checkbox" value="1" id="all"/>All | |
| <input type="checkbox" value="2" id="m"/>Monday | |
| <input type="checkbox" value="3" id="t"/>Tuesday | |
| <div id="qq"></div> <button id="bb">Click</button> | |
| var selected = new Array(); | |
| $(document).ready(function() | |
| { | |
| $('#all').on("click",function () { | |
| $("input[type='checkbox']").not("#all").each(function() | |
| { | |
| $(this).prop("checked",$("#all").is(":checked")); | |
| }); | |
| }); | |
| $('#bb').on("click", function(){ | |
| var selected = ""; | |
| $('input[type=checkbox]').each(function () { | |
| selected += "(" + $(this).val() + "-" + (this.checked ? "checked" : "not checked") + ")"; | |
| }); | |
| $('#qq').html(selected); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment