Skip to content

Instantly share code, notes, and snippets.

@rsutphin
Created March 14, 2013 00:18
Show Gist options
  • Select an option

  • Save rsutphin/5157757 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

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