Skip to content

Instantly share code, notes, and snippets.

@ursuleacv
Created September 20, 2013 18:40
Show Gist options
  • Select an option

  • Save ursuleacv/6641938 to your computer and use it in GitHub Desktop.

Select an option

Save ursuleacv/6641938 to your computer and use it in GitHub Desktop.
Getting all selected checkboxes in an array
<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