Advertisement
Guest User

Untitled

a guest
Apr 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. Checkbox:
  6. <label for="UK">
  7. <input type="checkbox" name="myCheck" value="UK" id="UK">United Kingdom
  8. </label>
  9. <label for="USA">
  10. <input type="checkbox" name="myCheck" value="USA">United States
  11. </label>
  12. <label for="IL">
  13. <input type="checkbox" name="myCheck" value="IL">Illinois
  14. </label>
  15. <label for="MA">
  16. <input type="checkbox" name="myCheck" value="MA">Massachusetts
  17. </label>
  18. <label for="UT">
  19. <input type="checkbox" name="myCheck" value="UT">Utah
  20. </label>
  21.  
  22. <input type="button" value="Click" id="btntest" />
  23.  
  24. <script>
  25. function myFunction() {
  26. var selchbox = [];
  27. var inputfields = document.getElementsByName("myCheck");
  28. var ar_inputflds = inputfields.length;
  29.  
  30. for (var i = 0; i < ar_inputflds; i++) {
  31. if (inputfields[i].type == 'checkbox' && inputfields[i].checked == true)
  32. selchbox.push(inputfields[i].value);
  33. }
  34. return selchbox;
  35.  
  36. }
  37.  
  38. document.getElementById('btntest').onclick = function(){
  39. var selchb = myFunction(); // gets the array returned by getSelectedChbox()
  40. alert(selchb);
  41. console.log(selchb);
  42. }
  43.  
  44.  
  45. </script>
  46.  
  47. </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement