What Are JavaScript Event Handlers?

JavaScript OnLoad, OnMouseOver, OnClick and More

Ana Kirk
The Definition of JavaScript Event Handlers

JavaScript is a very popular scripting/programming languages used by web developers worldwide to code client-side scripts that allow for various types of interactivity on web pages. JavaScript event handlers are a major part of working with this language and those who wish to learn to work with them should first understand what they are and what they can and cannot do.

An event is some type of action that is carried out by the web page visitor, the web browser, or perhaps even by another script. For example, when you move the mouse over an image or over a link, that is an event. A handler is a mechanism or a way to both capture and respond to an event. If the web developer wants an image to change when the mouse is hovered overed it, he or she can respond to such an event via JavaScript event handlers. They are written right in line with hypertext mark-up language (HTML) and used to interact with visitors in a variety of ways.

What Are Specific JavaScript Event Handlers?

There are various JavaScript event handlers to handle various actions and to allow a response to them. Some are used much more than others. Among the most popular JavaScript event handlers are: JavaScript onLoad, onMouseover, onMouseout, onClick and onSubmit. Remember, there's an event and there's a way to handle that event. The following description of JavaScript event handlers breaks this down a little better:

Event name: Load
Action: browser loading a web page
Event handler name: onLoad

Event name: Mouseover
Action: mouse moved over object in window
Event handler name: onMouseover

Event name: Mouseout
Action: moused moved off of an object
Event handler name: onMouseout

Event name: Click
Action: mouse button clicked
Event handler name: onClick

Event name: Submit
Action: a form is submitted (ie. contact form)
Event handler name: onSubmit

There are other JavaScript event handlers that are not used as often as these. They include: onReset, onFocus, onBlur, and onChange. The onReset handler resets a form such as a contact or registration form that has been completed. When a visitor changes selected data or data that is contained in a form element, this action or event is called "change." Focus refers to a visitor making a specific form element or an entire window active by clicking on it with a pointing device such as a mouse or by tabbing to it. Blur is simply the removal of focus.

You may have noticed that when visiting some web sites and wishing to enjoy certain kinds of interactivity, it is necessary to have JavaScript enabled so the scripts can run. Usually this is not a problem as it is generally enabled by default in your browser. However, you can disable it if you'd like and don't need it.

Source:
AAS - Web Development

Published by Ana Kirk

Ana Kirk is an emergency medical technician (EMT) and part-time web developer. She is also a back-up translator and author of study materials for a Christian ministry.  View profile

To comment, please sign in to your Yahoo! account, or sign up for a new account.