HTML DOM Input Reset object

HTMLWeb DevelopmentFront End Technology

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.


Following are the properties for the Input reset object −

autofocusTo set or return if the reset button should get focus automatically when the page loads or not.
defaultValueTo set or return the reset button default value.
disabledTo set or return if the reset button has been disabled, or not.
formTo return the reference of the form containing the reset button.
nameTo set or return the name attribute value of the reset button.
typeTo return the form element type for the reset button.
valueTo set or return the value attribute value of a slider control.


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

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


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");
Published on 19-Aug-2019 08:27:30