Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@Inforcekid 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