Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <body>
- Checkbox:
- <label for="UK">
- <input type="checkbox" name="myCheck" value="UK" id="UK">United Kingdom
- </label>
- <label for="USA">
- <input type="checkbox" name="myCheck" value="USA">United States
- </label>
- <label for="IL">
- <input type="checkbox" name="myCheck" value="IL">Illinois
- </label>
- <label for="MA">
- <input type="checkbox" name="myCheck" value="MA">Massachusetts
- </label>
- <label for="UT">
- <input type="checkbox" name="myCheck" value="UT">Utah
- </label>
- <input type="button" value="Click" id="btntest" />
- <script>
- function myFunction() {
- var selchbox = [];
- var inputfields = document.getElementsByName("myCheck");
- var ar_inputflds = inputfields.length;
- for (var i = 0; i < ar_inputflds; i++) {
- if (inputfields[i].type == 'checkbox' && inputfields[i].checked == true)
- selchbox.push(inputfields[i].value);
- }
- return selchbox;
- }
- document.getElementById('btntest').onclick = function(){
- var selchb = myFunction(); // gets the array returned by getSelectedChbox()
- alert(selchb);
- console.log(selchb);
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement