Javascript Reference - HTML DOM Input Radio disabled Property








The disabled property disables or enables a radio button.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = radioObject.disabled 

Set the disabled property.

radioObject.disabled=true|false 

Property Values

Value Description
true|false Disable or enable a radio button.
  • true - The radio button is disabled
  • false - Default. The radio button is not disabled




Return Value

A Boolean type value, true if the radio button is disabled, otherwise false.

Example

The following code shows how to get if a radio button is disabled.


<!DOCTYPE html>
<html>
<body>
Radio Button: <input type="radio" id="myRadio">
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--from  w w  w  . j a  v a 2 s.  c  o  m-->
    var x = document.getElementById("myRadio").disabled;
    document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to disable and enable a radio button.


<!DOCTYPE html>
<html>
<body>
<!--  w  ww . j av  a 2s.c o  m-->
Radio Button: <input type="radio" id="myRadio">

<button onclick="disable()">Disable radio button</button>
<button onclick="enable()">Enable radio button</button>

<script>
function disable() {
    document.getElementById("myRadio").disabled = true;
}
function enable() {
    document.getElementById("myRadio").disabled = false;
}
</script>

</body>
</html>

The code above is rendered as follows: