Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created October 3, 2019 00:43
Show Gist options
  • Save codingwithsara/8b370c2f29ed89e55904e561f6b5a1c2 to your computer and use it in GitHub Desktop.
Save codingwithsara/8b370c2f29ed89e55904e561f6b5a1c2 to your computer and use it in GitHub Desktop.
JS Checkboxes 3
<!DOCTYPE html>
<html lang="ja">
<head>
<!-- 省略 -->
</head>
<body>
<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>
</div>
<script>
function getValue() {
var checks = document.getElementsByClassName('checks');
var str = '';
for ( i = 0; i < 3; i++) {
if ( checks[i].checked === true ) {
str += checks[i].value + " ";
}
}
alert(str);
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment