HTML DOM Input Reset Object



The HTML DOM Input Reset object is associated with the <input> element with type “reset”. We can create and access an input element with type reset by using the createElement() and getElementById() method respectively.

Properties

Following are the properties for the Input reset object −

Property Description
autofocus To set or return if the reset button should get focus automatically when the page loads or not.
defaultValue To set or return the reset button default value.
disabled To set or return if the reset button has been disabled, or not.
form To return the reference of the form containing the reset button.
name To set or return the name attribute value of the reset button.
type To return the form element type for the reset button.
value To set or return the value attribute value of a slider control.

Example

Let us look at an example for the Input Reset object −

<!DOCTYPE html>
<html>
<head>
<script>
   function resetCreate() {
      var Res = document.createElement("INPUT");
      Res.setAttribute("type", "reset");
      document.body.appendChild(Res);
   }
</script>
</head>
<body>
<h1>Input Reset object</h1>
<p>Create an input field with type reset by clicking the below button</p>
<button onclick="resetCreate()">CREATE</button>
<br><br>
</body>
</html>

Output

This will produce the following output −

On clicking the CREATE button −

In the above example −

We have created a button CREATE that will execute the resetCreate() method when clicked by the user −

<button onclick="resetCreate()">CREATE</button>

The resetCreate() method uses the createElement() method of the document object to create the <input> element by passing “INPUT” as a parameter. The newly created input element is assigned to variable Res and using the setAttribute() method we create a type attribute with value reset.

Remember, setAttribute() creates the attribute and then assigns value if the attribute doesn’t exist previously. Finally using the appendChild() method on document body, we append the input element with type reset as the child of the body −

function resetCreate() {
   var Res = document.createElement("INPUT");
   Res.setAttribute("type", "reset");
   document.body.appendChild(Res);
}
Updated on: 2019-08-19T08:27:30+05:30

152 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements