SHARE
TWEET

Untitled

a guest Jan 22nd, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script type="text/javascript">
  2.     function validation() {
  3.         var inputs = document.querySelectorAll("[class^=class_]");
  4.         var hash = {};
  5.         var checked = 1;
  6.         for(var i = 0; i < inputs.length; i++) {
  7.             var counter = 0;
  8.             if(inputs[i].type == "checkbox" && inputs[i].offsetParent!== null) {
  9.                 if (hash[inputs[i].classList]) {
  10.                     counter = hash[inputs[i].classList];
  11.                 }
  12.                 if (inputs[i].checked) {
  13.                     counter = counter + 1;
  14.                 }
  15.                 hash[inputs[i].classList] = counter;
  16.             }
  17.         }
  18.         Object.keys(hash).forEach(function (key) {
  19.             var value = hash[key]
  20.             if(value == 0) {
  21.                 checked = 0
  22.             }
  23.         })
  24.         if(checked == 0) {
  25.             alert("You must check at least one checkbox.");
  26.             return false;
  27.         }
  28.     }
  29.     object.addEventListener("submit", validation());
  30. </script>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top