Saturday, April 30, 2011

JavaScript Event Handlers


When your users visit your website, they do things like click on things, hover over things etc. These are examples of what JavaScript calls events. Using JavaScript, you can respond to an event using Event Handlers. You can attach an event handler to the HTML element for which you want to respond to when a specific event occurs. For example, you could attach JavaScript'sonMouseover event handler to a button and specify some JavaScript to run whenever this event occurs against that button.
The HTML 4 specification defines 18 event handlers as listed below:
Event HandlerEvent that it handles
onBlurUser has left the focus of the object. For example, they clicked away from a text field that was previously selected.
onChangeUser has changed the object, then attempts to leave that field (i.e. clicks elsewhere).
onClickUser clicked on the object.
onDblClickUser clicked twice on the object.
onFocusUser brought the focus to the object (i.e. clicked on it/tabbed to it)
onKeydownA key was pressed over an element.
onKeyupA key was released over an element.
onKeypressA key was pressed over an element then released.
onLoadThe object has loaded.
onMousedownThe cursor moved over the object and mouse/pointing device was pressed down.
onMouseupThe mouse/pointing device was released after being pressed down.
onMouseoverThe cursor moved over the object (i.e. user hovers the mouse over the object).
onMousemoveThe cursor moved while hovering over an object.
onMouseoutThe cursor moved off the object
onResetUser has reset a form.
onSelectUser selected some or all of the contents of the object. For example, the user selected some text within a text field.
onSubmitUser submitted a form.
onUnloadUser left the window (i.e. user closes the browser window).

No comments:

Post a Comment