Javascript DOM HTML Form handle reset Event

Introduction

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

View in separate window

<!DOCTYPE html>
<html>
<body>
<form id="myForm" onreset="myAlertFunction()">
  First name: <input type="text" name="fname">
  <input type="button" onclick="myResetFunction()" value="Reset form">
</form>/*from w w w  .ja va2  s .c  om*/
<p id="demo"></p>

<script>
// Reset the text of an element in a form with id="myForm"
function myResetFunction() {
  document.getElementById("myForm").reset();
}

// Alert some text when the form is reset
function myAlertFunction() {
  document.getElementById("demo").innerHTML = "The form was reset";
}
</script>

</body>
</html>



PreviousNext

Related