Skip to content

Instantly share code, notes, and snippets.

@Vinlock
Last active September 30, 2015 21:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Vinlock/6356d728ff1a35c75e48 to your computer and use it in GitHub Desktop.
Save Vinlock/6356d728ff1a35c75e48 to your computer and use it in GitHub Desktop.
Personal Scripts / JQuery / JavaScript / Check if all of a certain class of checkboxes are checked and confirm with user it is okay for the ones not checked to be that way.
$('#inserting').submit(function(){
var confirms = ["true"];
// Class/Function to check if all values are the same. - http://stackoverflow.com/a/14832662
Array.prototype.allValuesSame = function() {
for(var i = 1; i < this.length; i++)
{
if(this[i] !== this[0])
return false;
}
return true;
}
$('.main_checkbox').each(function() {
if (!$(this).is(':checked')) {
var name = $(this).attr("value");
if (confirm("Are you sure it is okay that " + name + " is not checked??")) {
confirms.push("true");
}
else {
confirms.push("false");
}
}
});
if (!confirms.allValuesSame()) {
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment