HTML onsubmit Attribute

HTML onsubmit Attribute: The HTML onsubmit attribute is defined as it fires when a form is submitted.

HTML onsubmit Attribute

The HTML onsubmit attribute can be applied on <form> element.

Attribute Value

This attribute contains a single value script which works when onsubmit event call.

Browser Support

The HTML onsubmit attribute is supported by the following browsers:

  • Chrome
  • Firefox
  • Internet Explorer
  • Safari
  • Opera

Example: for <form> element

<!DOCTYPE html>
<html>
<body>
<form action="/action_page.php" onsubmit="myFunction()">
  Enter name: <input type="text" name="fname">
  <input type="submit" value="Submit">
</form>

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

</body>
</html>

Output:

HTML onsubmit attribute