If you implement an event handler as a function, then you can call it from other functions as needed. For example, we can build a form validator and associate it with the onSubmit event for the form.
We might want to invoke that validator when something else changes on the page or as a result of the user clicking on various buttons. Because the submission is still handled by the browser, invoking the form validation event handler won't submit the form unless it is called as a result an onSubmit event being triggered.
The form only gets submitted to the server if the form validator returns the correct Boolean flag value when it is invoked in response to an onSubmit trigger event.
There is another way to submit the form's contents. That is by calling the submit() method belonging to a Form object. That doesn't trigger an onSubmit event if it is called within the context of an onSubmit event handler. You could use this technique if you wanted the form contents to be submitted by some action other than clicking on a submit button.
See also: | Event handler, Event handler properties, Function call |
Prev | Home | Next |
Call-back event | Up | CanPut() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |