Javascript DOM HTML Form reset() Method

Introduction

Reset a form:

document.getElementById("myForm").reset();

Enter some text in the fields below, then press the "Reset form" button to reset the form.

View in separate window

<!DOCTYPE html>
<html>
<body>
<form id="myForm">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br><br>
  <input type="button" onclick="myFunction()" value="Reset form">
</form>/*from  ww w  .  j a v a  2s.  c  om*/

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

</body>
</html>

The reset() method resets the values of all elements in a form.

It is the same as clicking the Reset button.




PreviousNext

Related