Javascript DOM onsubmit Event

Introduction

Execute a JavaScript when a form is submitted:

When you submit the form, a function is triggered which alerts some text.

View in separate window

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" onsubmit="myFunction()">
  Enter name: <input type="text" name="fname">
  <input type="submit" value="Submit">
</form>//from   w  w  w. jav a  2  s .  c o  m

<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = "The form was submitted";
}
</script>

</body>
</html>

The onsubmit event occurs when a form is submitted.

Bubbles: Yes
Cancelable: Yes
Event type: Event
Supported HTML tags: <form>



PreviousNext

Related