Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!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(); 
  alert(selchb);
  console.log(selchb);
}
</script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
ssuryarpro
0viewers