HTML | DOM Option disabled Property

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output :

Before Clicking On Button :

After Clicking On Button:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


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

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : shubham_singh



Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.