JavaScript » eventhandler » onSubmit

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.


<FORM onSubmit="submitEvent()">

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

<FORM onSubmit="return validate(this)">

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: