Created
November 25, 2019 15:58
-
-
Save DonerKebab/932fe10211749c14937cf8a4e2ed7ec4 to your computer and use it in GitHub Desktop.
get selected value in radio button
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
<!DOCTYPE html> | |
<html> | |
<body> | |
<p>Please select your gender:</p> | |
<input type="radio" name="gender" id="r1" value="male"> Male<br> | |
<input type="radio" name="gender" id="r2" value="female"> Female<br> | |
<input type="radio" name="gender" id="r3" value="other"> Other<br> | |
<button onclick="selectValue()">Save</button> | |
<script> | |
function selectValue(){ | |
if (document.getElementById('r1').checked) { | |
console.log(document.getElementById('r1').value); | |
} else if (document.getElementById('r2').checked) { | |
console.log(document.getElementById('r2').value); | |
} else if (document.getElementById('r3').checked) { | |
console.log(document.getElementById('r3').value); | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment