Skip to content

Instantly share code, notes, and snippets.

@codingwithsara codingwithsara/index.html Secret
Created Oct 3, 2019

Embed
What would you like to do?
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
You can’t perform that action at this time.