|Lesson 5: Events|
Here is a limited list of events handlers (check for cross-browser issues):
[Note-setTimeout is a program defined event, as are onAbort and onError, yet they are still event handlers all the same]
2) Event Return Values
By adding a comparison to the onSubmit, we can create a form that will only go to the normal action when the comparison is met, and will return false otherwise preventing the normal action from occuring.
Return values depend upon the individual event handler, not following any structure for returning true or false, so it is advisable to study a good reference for individual event hanlder return values.
[Note- when using onMouseOver for a link to alter the status bar message, most browsers show the link addy in the status bar, so we must use "return true;" to insure our message takes precedence:
Events and event handlers can be written into a page in two main ways:
A) HTML Attributes
In the above example, we looked at the onSubmit event handler of the HTML form tag. As you can see, it is a virtual script section contained by the double quotes just as the arguments for any HTML attribute. To make it easier, you could define all the scriping within the onSubmit as a function in script tags in the head section of your document and call to the function with the event handler (modular).
[Note-scope is important for complex scripting, but only needs to be generally understood for 75% of all scripting]
Sample 5- Define and Alter Event Handlers
1) HTML used to incorporate the script
Notice that you can set event handlers either in your HTML attrbutes, or in a script section affecting the properites of the object the event handler is dependent upon, which also allows you to dynamically alter the event handlers on a page. Close attention to use of quotation marks is vital to incorporating scripting in HTML event hanlders!
Almost every object in the DOM can be affected in some way by event hanlders, either through the event handler being triggered by an event on the object in question, or through the scripts triggered by an event on any object [note-the object the event occurs on does not even have to be in the same DOM, but with browser read/write priveleges, can be contained within a completely seperate top level window]. The scope chain affected by event handlers is based upon the method by which the event handler is defined.
3) User Interaction