Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8" />
- <title>test</title>
- </head>
- <body>
- <form id="form">
- <input id="jour1" name="jour1" type="checkbox">
- Lundi
- <input id="jour2" name="jour2" type="checkbox">
- Mardi
- <input id="jour3" name="jour3" type="checkbox">
- Mercredi
- <input id="jour4" name="jour4" type="checkbox">
- Jeudi
- <input id="jour5" name="jour5" type="checkbox">
- Vendredi
- <input id="jour6" name="jour6" type="checkbox">
- Samedi
- <input id="jour7" name="jour7" type="checkbox">
- Dimanche
- <input type="submit" value="submit" />
- </form>
- <script type="text/javascript">
- var inputs = document.getElementsByTagName('input');
- var form = document.getElementById("form");
- function test() {
- var c = inputs.length;
- var n = 0;
- for(var i = 1; i < c; i++) {
- if(inputs[i].type == 'checkbox' && inputs[i].checked) {
- n++
- }
- }
- alert(n);
- }
- form.addEventListener('submit', function(e) {
- test();
- e.preventDefault();
- }, true);
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement