Created
August 16, 2021 14:02
-
-
Save burt202/69bfd65e4d359b95fe5ce7be2d2bdeca to your computer and use it in GitHub Desktop.
Getting radio values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<body> | |
<h1>Group 1</h1> | |
<div> | |
<input type="radio" id="group1-aaa" name="group1" value="aaa" /> | |
<label for="aaa">AAA</label> | |
</div> | |
<div> | |
<input type="radio" id="group1-bbb" name="group1" value="bbb" /> | |
<label for="bbb">BBB</label> | |
</div> | |
<div> | |
<input type="radio" id="group1-ccc" name="group1" value="ccc" /> | |
<label for="ccc">CCC</label> | |
</div> | |
<hr /> | |
<h1>Group 2</h1> | |
<div> | |
<input type="radio" id="group2-aaa" name="group2" value="aaa" /> | |
<label for="aaa">AAA</label> | |
</div> | |
<div> | |
<input type="radio" id="group2-bbb" name="group2" value="bbb" /> | |
<label for="bbb">BBB</label> | |
</div> | |
<div> | |
<input type="radio" id="group2-ccc" name="group2" value="ccc" /> | |
<label for="ccc">CCC</label> | |
</div> | |
<script type="text/javascript"> | |
const radioNodes = document.querySelectorAll('[type="radio"]') | |
function getRadiosWithValue(nodes, value) { | |
return Array.from(nodes).filter((r) => r.value === value) | |
} | |
console.log("filtered", getRadiosWithValue(radioNodes, "aaa")) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment