Latest web development tutorials

Form onsubmit event

Form Object Reference Form Object

Definition and Usage

onsubmit event called when the form is submitted.

grammar

onsubmit="JavaScriptCode"

参数 描述
JavaScriptCode 必须。事件触发后指定执行的 JavaScript 代码。


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support onsubmit event


Examples

Examples

When the submit button click to submit the form to display a pop-window frame:

<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"


Form Object Reference Form Object