English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML Reference Manual

HTML tag大全

HTML onsubmit event attribute

The submit event will be triggered when the user clicks the submit button ( <input type="submit"/> Element is triggered when the form is submitted.

HTML Event Attributes

Online Example

Run onsubmit when the form is submitted:

<!DOCTYPE html>
<html>
<head>
<title>HTML onsubmit event attribute usage (Basic Tutorial Website oldtoolbag.com)</>title
</>head
<body>
<p>After submitting the form, a prompt box will pop up.</>p
<form action="demo-form.php" onsubmit="myFunction()">
  Enter Name: <input type="text" name="fname">
  <input type="submit" value="Submit">
</form>
<script>
function myFunction() {
  alert("Form is submitted");
}
</script>
</body>
</html>
Test and see ‹/›

Browser Compatibility

IEFirefoxOperaChromeSafari

All major browsers support the onsubmit event attribute

Definition and Usage

The onsubmit attribute is triggered when a form is submitted.

The onsubmit attribute is only applicable to <form> elements.

HTML 4.01 and HTML5The differences between

No difference.

Syntax

<form onsubmit="script">

Attribute Value

ValueDescription
scriptSpecifies the script to be executed when the onsubmit event is triggered.
HTML Event Attributes