Created
March 14, 2013 00:18
-
-
Save rsutphin/5157757 to your computer and use it in GitHub Desktop.
Example of resetting an HTML radio button to unchecked using JavaScript.
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> | |
<head> | |
<style type="text/css"> | |
label { display: block; } | |
</style> | |
<body> | |
<form> | |
<label><input type="radio" name="q" id="radio-a" value="A"> A</label> | |
<label><input type="radio" name="q" id="radio-b" value="B"> B</label> | |
<label><input type="radio" name="q" id="radio-c" value="C"> C</label> | |
<a href="#" id="clear-button">Clear</a> | |
</form> | |
<script type="text/javascript"> | |
document.getElementById('clear-button').addEventListener('click', function () { | |
["radio-a", "radio-b", "radio-c"].forEach(function(id) { | |
document.getElementById(id).checked = false; | |
}); | |
return false; | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The part Clear should be
Clear