Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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