Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.09 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.     <head>
  4.         <meta charset="utf-8" />
  5.         <title>test</title>
  6.     </head>
  7.     <body>
  8.         <form id="form">
  9.             <input id="jour1" name="jour1" type="checkbox">
  10.             Lundi
  11.             <input id="jour2" name="jour2" type="checkbox">
  12.             Mardi
  13.             <input id="jour3" name="jour3" type="checkbox">
  14.             Mercredi
  15.             <input id="jour4" name="jour4" type="checkbox">
  16.             Jeudi
  17.             <input id="jour5" name="jour5" type="checkbox">
  18.             Vendredi
  19.             <input id="jour6" name="jour6" type="checkbox">
  20.             Samedi
  21.             <input id="jour7" name="jour7" type="checkbox">
  22.             Dimanche
  23.             <input type="submit" value="submit" />
  24.         </form>
  25.         <script type="text/javascript">
  26.             var inputs = document.getElementsByTagName('input');
  27.             var form = document.getElementById("form");
  28.  
  29.             function test() {
  30.                 var c = inputs.length;
  31.                 var n = 0;
  32.                 for(var i = 1; i < c; i++) {
  33.                     if(inputs[i].type == 'checkbox' && inputs[i].checked) {
  34.                         n++
  35.                     }
  36.                 }
  37.                 alert(n);
  38.             }
  39.  
  40.  
  41.             form.addEventListener('submit', function(e) {
  42.  
  43.                 test();
  44.                 e.preventDefault();
  45.             }, true);
  46.  
  47.         </script>
  48.     </body>
  49. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement