DHTML Events
Fires when a FORM is about to be submitted.
Inline HTML |
<FORM onsubmit = "handler" ... > |
All platforms |
Event property |
form.onsubmit = handler |
ECMA-262 Language Specification |
Named script |
<script FOR=form EVENT=onsubmit> |
Internet Explorer® only |
A submit event occurs when a form is submitted. This event only applies to the FORM element.
This event can be overridden by returning false in the event handler. This capability is useful for the developer who wants to validate data on the client side to prevent invalid data from being submitted to the server.
If the event handler is called by the onsubmit attribute of the form object, the code must explicitly request the return value using the return
function, and the event handler must provide an explicit return value for each possible code path in the event handler function.
Note that submitting a form thru script using the submit method does not invoke the onsubmit event handler.
While event handlers in the Document Object Model do not receive parameters directly, the handler can query the event object for data.
Event Object Properties
altKey |
Retrieves the current state of the ALT key. |
ctrlKey |
Retrieves the state of the CTRL key. |
returnValue |
Sets or retrieves the return value from the event. |
shiftKey |
Retrieves the state of the SHIFT key. |
srcElement |
Retrieves the object that fired the event. |
type |
Retrieves the event name from the event object. |
The example demonstrates how to request the return value using the return function when using onsubmit on a form.
<form onsubmit = "return validateForm(this)">
... form control definitions here ...
</form>
Show me
FORM
action, method, Data Entry Validation Routines