Skip to content

Instantly share code, notes, and snippets.

@surferxo3
Last active July 26, 2020 11:41
Show Gist options
  • Save surferxo3/0b3825300a28d6eaebeb3f617f3f3153 to your computer and use it in GitHub Desktop.
Save surferxo3/0b3825300a28d6eaebeb3f617f3f3153 to your computer and use it in GitHub Desktop.
Select / Deselect All Checkboxes
// change selection_all checkbox state
$("[name=\'selection[]\']").change(function() {
var state = true;
if ($("[name=\'selection[]\']:checked").length != $("[name=\'selection[]\']").length) {
state = false;
} else {
state = true;
}
$("[name=\'selection_all\']").prop("checked", state);
});
// change selection[] checkboxes state
$("[name=\'selection_all\']").change(function() {
$("[name=\'selection[]\']").prop("checked", $(this).is(":checked"));
});
// get checked selection[] checboxes as string
$("#w0").submit(function() {
var checkedIds = $("[name=\'selection[]\']:checked").map(function() {
return $(this).val();
}).get().join();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment