HTML DOM Input Radio disabled Property


The HTML DOM Input Radio disabled property is used for setting or returning if the radio button should be disabled or not. It uses boolean values with true representing the element should be disabled and false otherwise. The disabled property is set to false by default. The disabled element is greyed out by default and is unclickable .

Syntax

Following is the syntax to −

Set the disabled property.

radioObject.disabled = true|false;

Here, true= the radio button is disabled and false=the radio button is not disabled. It is false by default.

Example

Let us look at an example for the Input radio disabled property −

Live Demo

<!DOCTYPE html>
<html>
<body>
<h1>Input radio disabled Property</h1>
<form>
FRUIT:
<input type="radio" name="fruits" id="Mango">Mango
</form>
<p>Disable the above radio button by clicking on the DISABLE button</p>
<button type="button" onclick="disableRadio()">DISABLE</button>
<p id="Sample"></p>
<script>
   function disableRadio() {
      document.getElementById("Mango").disabled=true;
      document.getElementById("Sample").innerHTML = "The radio button is now disabled" ;
   }
</script>
</body>
</html>

Output

This will produce the following output −

On clicking the DISABLE button −

In the above example −

We have first created an input element inside a form with type=”radio”, name=”fruits”, id=”Mango”.

<form>
FRUIT:
<input type="radio" name="fruits" id="Mango">Mango
</form>

We then created a DISABLE button that will execute the disableRadio() method when clicked by the user −

<button type=”button” onclick="disableRadio()">DISABLE</button>

The disableRadio() method gets the input element with type radio using the getElementById() method and sets its disabled property to true. This greys the radio button and the user can no longer interact with it:

function disableRadio() {
   document.getElementById("Mango").disabled=true;
   document.getElementById("Sample").innerHTML = "The radio button is now disabled" ;
}

Updated on: 15-Feb-2021

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements