Skip to content
Related Articles

Related Articles

HTML | DOM Option disabled Property
  • Last Updated : 15 Apr, 2019

The DOM Option disabled Property is used to set or return whether the value of an option would be disabled or not. The disabled attribute for the element in HTML is used to specify that the option value is disabled. A disabled option is un-clickable and unusable. It is a boolean attribute.

Syntax:

  • It is used to return the disabled property.
    optionObject.disabled
  • It is used to set the disabled property.
    optionObject.disabled = true|false

Property Values:

  • true:It defines that option is disabled.
  • false: It defines that option value is not disabled. It has a Default value.

Return Value: It returns a boolean value which represent that option value is disabled or not.

Example-1: This Example illustrate how to set the Property.






<!DOCTYPE html>
<html>
  
<head>
    <title>DOM option disabled Property</title>
    <style>
        body {
            text-align: center;
        }
          
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>DOM option disabled Property</h2>
    <select id="GFG">
        <option>Choose an option</option>
        <option value="html">HTML</option>
        <option value="java">JAVA</option>
        <option value="C++">C++</option>
        <option value="php">PHP</option>
        <option value="perl">PERL</option>
    </select>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <button onclick="myGeeks()">Submit</button>
  
    <script>
        function myGeeks() {
            
            // Set disabled property "true".
            var x = document.getElementById(
             "GFG").options[2].disabled = true;
        }
    </script>
  
</body>
  
</html>

Output :

Before Clicking On Button :

After Clicking On Button:

Example-2 : This Example illustrate how to return the disabled property.




<!DOCTYPE html>
<html>
  
<head>
    <title>DOM option disabled Property</title>
    <style>
        body {
            text-align: center;
        }
          
        h1 {
            color: green;
        }
    </style>
</head>
  
<body>
    <h1>GeeksforGeeks</h1>
    <h2>DOM option disabled Property</h2>
    <select id="GFG">
        <option>Choose an option</option>
        <option value="html">HTML</option>
        <option value="java">JAVA</option>
        <option value="C++">C++</option>
        <option value="php">PHP</option>
        <option value="perl">PERL</option>
    </select>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <br>
    <button onclick="myGeeks()">Submit</button>
    <p id="sudo" style="font-size:25px;color:green;">
  </p>
    
    <script>
        function myGeeks() {
            
            // Return disabled property.
            var x = document.getElementById(
              "GFG").options[2].disabled;
            
            document.getElementById("sudo").innerHTML = x;
        }
    </script>
  
</body>
  
</html>

Output:

Before Clicking On Button:

After Clicking On Button:

Supported Browsers: The browser supported by DOM option disabled Property are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari
My Personal Notes arrow_drop_up
Recommended Articles
Page :