How to uncheck checked radio button [duplicate]

This simple script allows you to uncheck an already checked radio button. Works on all javascript enabled browsers.

var allRadios = document.getElementsByName('re');
var booRadio;
var x = 0;
for(x = 0; x < allRadios.length; x++){
  allRadios[x].onclick = function() {
    if(booRadio == this){
      this.checked = false;
      booRadio = null;
    } else {
      booRadio = this;
    }
  };
}
<input type="radio" class="radio-button" name="re">
<input type="radio" class="radio-button" name="re">
<input type="radio" class="radio-button" name="re">

Leave a Comment