The Wayback Machine - https://web.archive.org/web/20240717024431/https://www.geeksforgeeks.org/how-to-remove-disabled-attribute-from-html-input-element-using-javascript/
Open In App

How to remove “disabled” attribute from HTML input element using JavaScript ?

Last Updated : 29 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In HTML, we use input elements for user input. The ‘disabled’ property helps prevent interaction with these elements. For example, if we only want users over 18 to input their Adhar card numbers, we can use JavaScript to remove the ‘disabled’ attribute when the user enters an age greater than 18. This ensures that users can only input Adhar card numbers if they meet the specified age requirement. Here, we will learn various approaches to remove the disabled attribute from the HTML input element using JavaScript.

Using the removeAttribute() method

The ‘removeAttribute( )’ method in JavaScript is used to eliminate a specific attribute, such as “disabled,” from an HTML element, enabling user interaction.

Syntax:

document.getElementById('geeks').removeAttribute('disabled');

Example: This example implements the use of the removeAttribute() method to remove the disabled attribute from the HTML input element.

html




<!DOCTYPE html>
<html>
 
<head>
    <title>
        To remove “disabled” attribute from
        HTML input element
    </title>
    <style>
        body {
            text-align: center;
        }
 
        h1 {
            color: green;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <p>Click on the button to remove disabled attribute</p>
    Type:
    <input id="input" disabled /><br><br>
    <button onclick="myGFG()">Click Here</button>
    <p id="gfg"></p>
    <script>
        let down = document.getElementById("gfg");
 
        function myGFG() {
            document.getElementById('input').removeAttribute('disabled');
            down.innerHTML = "Disabled Attribute removed";
        }
    </script>
</body>
 
</html>


Output:

gty

Modifying the ‘disabled’ property

In this method, we change the ‘disabled’ property value to ‘false’ instead of removing the ‘disabled’ property itself from an HTML element. The ‘disabled’ property, by default, is ‘true’, and setting it to ‘false’ achieves the same result as removing the ‘disabled’ property.

Example: This example implements the use of thedisabled property to remove the disabled attribute from the HTML input element.

html




<!DOCTYPE HTML>
<html>
 
<head>
    <title>
        To remove “disabled” attribute from
        HTML input element
    </title>
    <style>
        body {
            text-align: center;
        }
 
        h1 {
            color: green;
        }
    </style>
</head>
 
<body>
    <h1>GeeksforGeeks</h1>
    <p>Click on the button to remove disabled attribute</p>
    Type:
    <input id="input" disabled /><br><br>
    <button onclick="myGFG()">Click Here</button>
    <p id="gfg"></p>
    <script>
        let down = document.getElementById("gfg");
 
        function myGFG() {
            let input = document.getElementsByClassName('inputClass');
            for (var i = 0; i < input.length; i++) {
                input[i].disabled = false;
            }
            down.innerHTML = "Disabled Attribute removed";
        }
    </script>
</body>
 
</html>


Output:



Similar Reads

HTML &lt;input&gt; disabled Attribute
The disabled attribute for &lt;input&gt; element in HTML is used to specify that the input field is disabled. A disabled input is un-clickable and unusable. It is a boolean attribute. The disabled &lt;input&gt; elements are not submitted in the form. Syntax: &lt;input disabled&gt; Example: C/C++ Code &amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;g
1 min read
Which attribute is used to disabled the specific input field in HTML Form ?
HTML5 introduced many attributes that are used for developing an efficient webpage. In this article, we will learn to disable the particular input field by using the "disable" attribute with the specific type of input. The disabled attribute is a boolean attribute that is used to vandalize the input field. A disabled input is un-clickable and unusa
1 min read
JQuery | Remove “disabled” attribute from an element
There is an Input Element which is disabled, the task is to enable it using JQuery. Here are a few examples discussed. To understand example first few methods to know. JQuery prop() method This method set/return properties and values of selected elements. If we use this method to return the property value, it will return the value of the FIRST sele
2 min read
How to specify whether an input element should have autocomplete disabled or not ?
The autocomplete attribute specifies whether an autocomplete input field should be enabled. The browser can predict the value using autocomplete. The browsing options to fill in the field, based on earlier typed values, should be shown for the user while typing a field. If the autocomplete feature is enabled, the browser will suggest values based o
2 min read
How to specify that an input element should be disabled?
The disabled attribute for &lt;input&gt; element is used to specify that the input field is disabled. A disabled input is un-clickable and unusable. It is a boolean attribute. The disabled &lt;input&gt; elements are not submitted in the form. Syntax:&lt;input disabled&gt;Example: In this example, to specify that an input element should be disabled
1 min read
HTML | disabled Attribute
The disabled attribute in HTML indicates whether the element is disabled or not. If this attribute is set, the element is disabled. The disabled attribute is usually drawn with grayed-out text. If the element is disabled, it does not respond to user actions, it cannot be focused. It is a boolean attribute. Usage: It can be used on the following ele
3 min read
HTML &lt;select&gt; disabled Attribute
The disabled attribute for &lt;select&gt; element in HTML is used to specify that the select element is disabled. A disabled drop-down list is un-clickable and unusable. It is a boolean attribute. Syntax: &lt;select disabled&gt;option values...&lt;/select&gt; Example: C/C++ Code &amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;gt; &amp;lt;head&amp;gt
1 min read
HTML &lt;option&gt; disabled Attribute
The disabled attribute for &lt;option&gt; 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: &lt;option disabled&gt;option values...&lt;/option&gt; Example: C/C++ Code &amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;gt; &amp;lt;head&amp;gt; &amp;lt;
1 min read
HTML &lt;textarea&gt; disabled Attribute
The disabled attribute for &lt;textarea&gt; element in HTML is used to specify that the text area element is disabled. A disabled text area is un-clickable and unusable. It is a boolean attribute. Syntax: &lt;textarea disabled&gt;text content...&lt;/textarea&gt; Example: C/C++ Code &amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;gt; &amp;lt;head
1 min read
HTML &lt;fieldset&gt; disabled Attribute
The disabled attribute for &lt;fieldset&gt; element in HTML is used to specify that the group of related form elements is disabled. A disabled fieldset is un-clickable and unusable. It is a boolean attribute. Syntax: &lt;fieldset disabled&gt;fieldset content...&lt;/fieldset&gt; Example: C/C++ Code &amp;lt;!DOCTYPE html&amp;gt; &amp;lt;html&amp;gt;
1 min read
three90RightbarBannerImg