Javascript Reference - HTML DOM Input Reset Object








The Input Reset object represents an HTML <input> element with type="reset".

Example

We can access an <input> element with type="reset" by using getElementById().


<!DOCTYPE html>
<html>
<body>
<input type="reset" id="myReset" value="Reset the form">
<!--from  w  w w  .j a  v a  2  s .c om-->
<button onclick="myFunction()">test</button>

<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("myReset").value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

We can create an <input> element with type="reset" by using the document.createElement() method.


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!-- w  w w.  j a v  a2  s .co  m-->
<script>
function myFunction() {
    var x = document.createElement("INPUT");
    x.setAttribute("type", "reset");
    document.body.appendChild(x);
}
</script>

</body>
</html>

The code above is rendered as follows:





Input Reset Object Properties

Property Description
autofocus Sets or gets whether a reset button can auto focus when the page loads
defaultValue Sets or gets the default value of a reset button
disabled Disable or enable the reset button
form Get the form that contains the reset button
name Sets or gets the name attribute of a reset button
type Get type string of the reset button
value Sets or gets the value attribute of the reset button

Standard Properties and Events

The Input Reset object supports the standard properties and events.