HTML DOM Input Reset disabled property


The HTML DOM Input reset disabled property is used for setting or returning if the reset button should be disabled or not. It uses boolean values, with true representing the reset button should be disabled and false otherwise. The disabled property is set to false by default. The disabled element is greyed out by default and is unclickable.

Syntax

Following is the syntax for −

Setting the disabled property −

resetObject.autofocus = true|false

Here, true=reset button is disabled and false=the reset button is not disabled. It is false by default.

Example

Let us look at an example for the Input reset disabled property −

 Live Demo

<!DOCTYPE html>
<html>
<body>
<h1>Input reset disabled Property</h1>
<form style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id="Age"> <br><br>
<input type="reset" id="RESET1">
</form>
<p>Disable the above reset button by clicking on the DISABLE button</p>
<button type="button" onclick="disableReset()">DISABLE</button>
<p id="Sample"></p>
<script>
   function disableReset() {
      document.getElementById("RESET1").disabled=true;
      document.getElementById("Sample").innerHTML = "The reset button is now disabled" ;
   }
</script>
</body>
</html>

Output

This will produce the following output −

On clicking the DISABLE button −

In the above example −

We have created an <input> element with type=”reset”, id=”RESET1”. Clicking on this button will reset the form data. This button is inside a form that contains two text fields and the form also has an inline style applied to it −

<form style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id="Age"> <br><br>
<input type="reset" id="RESET1">
</form>

We then created a button DISABLE that will execute the disableReset() method when clicked by the user −

<button type="button" onclick="disableReset()">DISABLE</button>

The disableReset() method gets the input element with type reset using the getElementById() method and sets its disabled property to true. This makes the reset button unclickable and the user can no longer interact with it. It has turned grey now −

function disableReset() {
   document.getElementById("RESET1").disabled=true;
   document.getElementById("Sample").innerHTML = "The reset button is now disabled" ;
}
raja
Published on 22-Aug-2019 16:25:57
Advertisements