Javascript DOM onsubmit Event via HTML Tag onsubmit attribute

Introduction

This example demonstrates how to assign an "onsubmit" event to a form element.

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>/* w  w  w . j  a v  a  2s  .  com*/

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

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



PreviousNext

Related