Form onsubmitEvent
Form Object
Definition and Usage
The onsubmit event is triggered when a form is submitted.
Syntax
onsubmit="JavaScriptCode"
| Parameter | Description |
|---|---|
| JavaScriptCode | Required. Specifies the JavaScript code to execute after the event is triggered. |
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the onsubmit event
Example
Example
Display a popup box after clicking the submit button to submit the form:
<html>
<head>
<script>
function greeting()
{
alert("Welcome " + document.forms["frm1"]["fname"].value + "!")
}
</script>
</head>
<body>
What is your name?<br>
<form name="frm1" action="submit.htm" onsubmit="greeting()">
<input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>
</html>
<head>
<script>
function greeting()
{
alert("Welcome " + document.forms["frm1"]["fname"].value + "!")
}
</script>
</head>
<body>
What is your name?<br>
<form name="frm1" action="submit.htm" onsubmit="greeting()">
<input type="text" name="fname">
<input type="submit" value="Submit">
</form>
</body>
</html>
Try it Yourself »
Form Object Other Extensions