Open In App

HTML | DOM Option disabled Property

Improve
Improve
Like Article
Like
Save
Share
Report

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. 

html




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

html




<!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 version 1 and above
  • Edge version 12 and above
  • Firefox version 1 and above
  • Internet Explorer 
  • Opera 
  • Safari


Last Updated : 21 Jun, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads