Last active
April 25, 2017 10:29
-
-
Save ssuryar/3d93344913fa7c7d083e7ad5c470000c to your computer and use it in GitHub Desktop.
// source http://jsbin.com/paruvoz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment