JavaScript » eventhandler » onSubmit

Syntax:
onSubmit = myJavaScriptCode

Event handler for Form

The onSubmit event handler is used to execute specified JavaScript code whenever the user submits a form, and as such, is included within the HTML <FORM> tag. The onSubmit event handler uses the following properties of the Event object:
 
type - indicates the type of event.
target - indicates the target object to which the event was sent.

Examples

Code:
<FORM onSubmit="submitEvent()">
Explanation:

In this example, the onSubmit event handler calls the 'submitEvent' function.

Code:
<FORM onSubmit="return validate(this)">
Explanation:

If you want to validate the information in the form and only allow it to be submitted if it meets your requirements, you will need to put a return statement that returns false in the event handler, as in this example using the 'validate' function.

See Also: