Javascript Reference - HTML DOM Fieldset disabled Property








The disabled property sets or gets whether a fieldset is disabled.

If this property is set, the form elements in the fieldset are disabled.

Browser Support

disabled Yes Yes Yes Yes Yes

Syntax

Return the disabled property.

var v = fieldsetObject.disabled 

Set the disabled property.

fieldsetObject.disabled=true|false 




Property Values

Value Description
true|false Specifies whether a fieldset should be disabled
  • true - The fieldset is disabled
  • false - Default. The fieldset is not disabled

Return Value

A Boolean type value, true if the fieldset is disabled, otherwise it returns false.

Example

The following code shows how to find out if a fieldset is disabled or not.


<!DOCTYPE html>
<html>
<body>
<form>
  <fieldset id="myFieldset" disabled>
    <legend>Information:</legend>
    Name: <input type="text"><br>
    Email: <input type="text"><br>
    Date of birth: <input type="text">
  </fieldset>
</form><!--from   ww w .  j av  a2  s.  co m-->
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
    var x = document.getElementById("myFieldset").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 fieldset.


<!DOCTYPE html>
<html>
<body>
<!--from   w ww  .  j  a va2s  . c o m-->
<form>
  <fieldset id="myFieldset">
    <legend>Information:</legend>
    Name: <input type="text"><br>
    Email: <input type="text"><br>
    Date of birth: <input type="text">
  </fieldset>
</form><br>
<button onclick="disableField()">Disable fieldset</button>
<button onclick="undisableField()">Undisable fieldset</button>
<script>
function disableField() {
    document.getElementById("myFieldset").disabled = true;
}

function undisableField() {
    document.getElementById("myFieldset").disabled = false;
}
</script>

</body>
</html>

The code above is rendered as follows: