onsubmit = myFunction(); - Javascript DOM Event

Javascript examples for DOM Event:Element Event Attribute

Description

The onsubmit event occurs when a form is submitted.

Summary

Bubbles Yes
Cancelable Yes
Supported HTML tags: <form>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" action="/action_page.php">
  Enter name: <input type="text" name="fname">
  <input type="submit" value="Submit">
</form>// ww w  .  j  ava  2s  .  c o  m

<script>
document.getElementById("myForm").onsuspend = function() {myFunction()};

function myFunction() {
    console.log("The form was submitted");
}
</script>

</body>
</html>

Related Tutorials