Form onsubmitEvent

Form 对象参考手册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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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>

Try it Yourself »


Form 对象参考手册Form Object Other Extensions