Last active
September 30, 2015 21:15
-
-
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.
This file contains 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
$('#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