Skip to content

Instantly share code, notes, and snippets.

Created October 3, 2019 01:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
JS Checkboxes 4
<!DOCTYPE html>
<html lang="ja">
<meta charset="utf-8">
.container {
width: 300px;
margin: 100px auto;
font-size: 20px;
button {
margin-top: 40px;
<div class="container">
<input type="checkbox" class="checks" value="あいうえお"> あ____<br>
<input type="checkbox" class="checks" value="かきくけこ"> か_____<br>
<input type="checkbox" class="checks" value="さしすせそ"> さ_____<br>
<button onclick="getValue()">値を取得</button>
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