Skip to content

Instantly share code, notes, and snippets.


codingwithsara/index.html Secret

Last active Nov 8, 2018
What would you like to do?
How to get the values of checked checkboxes in JavaScript
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Get Check Box Value</title>
.container {
margin: 100px 50px;
font-size: 20px;
<div class="container">
<input type="checkbox" class="checks" value="Apple"> A____<br>
<input type="checkbox" class="checks" value="Banana"> B_____<br>
<input type="checkbox" class="checks" value="Carrot"> C_____<br>
<a href="#" onclick="getValue();return false;">Get Value</a>
function getValue() {
var checks = document.getElementsByClassName('checks');
var str = '';
for ( i = 0; i < 3; i++) {
if ( checks[i].checked === true ) {
str += checks[i].value + " ";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment