HTML onsubmit Event Attribute

Description

The event attribute onsubmit allows you to set the script to fire when the form is submitted.

Syntax

<element onsubmit="script">

Values

  • scriptThe name of the script to use when the event has been triggered.

Example

<!DOCTYPE html> 
  <html> 
    <head>
      <title>onsubmit event</title> 
    </head> 
    <body> 
    <form action="#" onsubmit="testFunction()" >
    Email us something: <input type="text" name="mail"> 
    <input type="submit" value="Submit"> 
    </form> 
<script> 
function testFunction() { 
  alert ( "The form has been submitted!" ); 
} 
</script> 
  </body> 
</html>

Supported Tags

<form> and <keygen>

Browser Support

Desktop
Explorer Edge Chrome Firefox Opera Safari
YesYesYesYesYesYes
Tablets / Mobile
Android Chrome Firefox Opera Safari Samsung
YesYesYesYesYesYes