home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference

Form.onsubmit() Handler


Form.onsubmit() Handler---invoked when a form is submitted


Navigator 2.0, Internet Explorer 3.0


    onSubmit="handler-statements" a definition of the handler
    ...attributes...  other attributes here
form.onsubmit a reference to the handler
form.onsubmit();  an explicit invocation of the handler


onsubmit() is an event handler which is invoked when the form it is associated with is submitted, either when the user clicks a Submit button object, or when the submit() method is called for the form. This event handler is defined by the onSubmit attribute of the <FORM> tag that defines a form. The value of the attribute may be any number of JavaScript statements, separated by semicolons; these statements will be executed when the form is submitted.

A typical use of the onsubmit() event handler is to check that the user's input is valid before sending it over the network to a server. If the data is not valid, the onsubmit() handler may cancel form submission by returning the value false. If the handler returns any other value, or returns no value at all then the form will be submitted normally.


Whenever you use the onsubmit() event handler to cancel the submission of a form, you should be sure to notify the user why the submission was canceled, so that they can correct the problem. Window.alert() is a useful way to provide this information to the user.

Previous Home Next
Form.onreset() Book Index Form.reset()

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell