HTML event attribute onsubmit








The onsubmit attribute event is triggered when a form is submitted.

What's new in HTML5

None.

Syntax

<form onsubmit="script">

Supported Tags

<form>, <keygen>

Click to view the demo

Browser compatibility

onsubmit Yes Yes Yes Yes Yes




Example

<!DOCTYPE html>
<html>
<body>
<!--from   w  w  w .j  a v a2s.  c om-->
<form action="a.php" onsubmit="myFunction()">
  Enter name: <input type="text" name="fname">
  <input type="submit" value="Submit">
</form>

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

</body>
</html>

Click to view the demo