Javascript Reference - HTML DOM Form reset() Method








The reset() method resets the values of all elements in a form in the same way as clicking the Reset button.

Browser Support

reset Yes Yes Yes Yes Yes

Syntax

formObject.reset()

Parameters

None.





Return Value

No return value.

Example

The following code shows how to reset a form.


<!DOCTYPE html>
<html>
<body>
<form id="myForm">
  First name: <input type="text" name="fname"><br>
  <input type="button" onclick="myFunction()" value="Reset form">
</form><!--from   ww w  .j  av  a  2  s.  co  m-->

<script>
function myFunction() {
    document.getElementById("myForm").reset();
}
</script>

</body>
</html>

The code above is rendered as follows: