HTML event attribute onsubmit

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

What's new in HTML5



<form onsubmit="script">

Supported Tags

<form>, <keygen>

Click to view the demo

Browser compatibility

onsubmit Yes Yes Yes Yes Yes


<!DOCTYPE html>
<!--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">

function myFunction() {
    console.log("The form was submitted");


Click to view the demo