Uncheck Radio Button Dynamically with JavaScript

In this tutorial we will learn How To Uncheck Radio Button Dynamically with JavaScript. JavaScript getElementById() method, onclick event and checked property can be used to uncheck radio button dynamically.

getElementById() method

JavaScript getElementById() method selects or targets the HTML element using it's id.

In this example getElementById() method is used to select the radio button with help of it's id.

onclick event

onclick event triggers the click event for HTML tag or it attaches the JavaScript function with click event.

In this example onclick event is used to execute a JavaScript function on click of button to dynamically uncheck the radio button.

checked property

JavaScript checked property either checks or unchecks the radio button or HTML checkbox or it is used to check the current state of these two input elements.

In this example checked property is used to uncheck the radio button.


HTML Code is given below, in this code we have two radio buttons with two labels and two button tags with onclick event to execute two JavaScript functions.

<!DOCTYPE html>
<title>Unheck Radio Button Dynamically with JavaScript</title>
<label for="male">Male</label> 
<input type="radio" id="male" value="male" name="gender">   
<label for="female">Female</label>      
<input type="radio" id="female" value="female" name="gender">
<button onclick="uncheckMale()">Uncheck Male</button>   
<button onclick='uncheckFemale()'>Uncheck Female</button>    
<script src="script.js"></script>    

JavaScript Code

Take a look at the JavaScript code, in this code getElementById() method is used to select the radio button and checked property is used to uncheck radio button.

Two separate functions are used to uncheck both radio buttons.

function uncheckMale()
    var radio = document.getElementById('male');
    radio.checked = false;
function uncheckFemale()
    var radio = document.getElementById('female');
    radio.checked = false;


Video Tutorial

Watch video tutorial on How To Uncheck Radio Button with JavaScript.

Change font-size using JavaScript Get Font Size of any Tag using JavaScript Change Position of HTML Element using JavaScript How to Change Image on Hover with JavaScript How to Disable Button by Class Name in JavaScript How To Change Image Size with JavaScript How to change Image opacity with JavaScript How to Change image src on click with JavaScript How to get the lang attribute value in JavaScript How to Get attribute Value using JavaScript How To Check if Attribute Exists or not with JavaScript How To Count number of links on Page with JavaScript How To Scroll Page to Bottom using JavaScript How To Detect Shift Key Press with JavaScript Change Text Color On Hover with JavaScript Hide and Show div using JavaScript Get Button text with JavaScript Get textarea value with JavaScript Get table row Height with JavaScript Auto Increase width of input field with JavaScript Set Textarea maxLength with JavaScript Set Textarea Value with JavaScript JavaScript Count list items JavaScript set input field value Count Button Clicks with JavaScript Scroll Page to the Top on Click with JavaScript