Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Created March 14, 2013 00:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save rsutphin/5157757 to your computer and use it in GitHub Desktop.
Save rsutphin/5157757 to your computer and use it in GitHub Desktop.
Example of resetting an HTML radio button to unchecked using JavaScript.
<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>
@Inforcekid
Copy link

Inforcekid commented Mar 5, 2019

The part Clear should be
Clear

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment