HTML DOM Input Reset type property

HTMLWeb DevelopmentFront End Technology

The HTML DOM Input Reset type property is associated with the input element having its type=”reset”. It will always return reset for the input reset element.

Syntax

Following is the syntax for reset type property −

resetObject.type

Example

Let us look at an example for the reset type property −

<!DOCTYPE html>
<html>
<body>
<h1>Input reset type 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>Get the above input element type by clicking the below button</p>
<button type="button" onclick="resetType()">GET Type</button>
<p id="Sample"></p>
<script>
   function resetType() {
      var P=document.getElementById("RESET1").type;
      document.getElementById("Sample").innerHTML = "The type for the input field is: "+P ;
   }
</script>
</body>
</html>

Output

This will produce the following output −

On clicking the GET Type property −

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 “GET Type” that will execute the resetType() method when clicked by the user −

<button type="button" onclick="resetType()">GET Type</button>

The resetType() method gets the input element using the getElementById() method and assigns its type attribute value to variable P. This variable is then displayed in the paragraph with id “Sample” using its innerHTML property −

function getType() {
   var P = document.getElementById("RESET1").type;
   document.getElementById("Sample").innerHTML = "The type for the input field is : "+P;
}
raja
Published on 19-Aug-2019 12:08:05
Advertisements