Open In App

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: 



optionObject.disabled
optionObject.disabled = true|false

Property Values:

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:


Article Tags :