Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/javascript">
- function validation() {
- var inputs = document.querySelectorAll("[class^=class_]");
- var hash = {};
- var checked = 1;
- for(var i = 0; i < inputs.length; i++) {
- var counter = 0;
- if(inputs[i].type == "checkbox" && inputs[i].offsetParent!== null) {
- if (hash[inputs[i].classList]) {
- counter = hash[inputs[i].classList];
- }
- if (inputs[i].checked) {
- counter = counter + 1;
- }
- hash[inputs[i].classList] = counter;
- }
- }
- Object.keys(hash).forEach(function (key) {
- var value = hash[key]
- if(value == 0) {
- checked = 0
- }
- })
- if(checked == 0) {
- alert("You must check at least one checkbox.");
- return false;
- }
- }
- object.addEventListener("submit", validation());
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement