instructional systems
Index:
[Session11] JavaScript 1 (Interactive page)
1 Chapter1
2 Chapter2
3 Chapter3
--3.3 Application of Handling
4 Chapter4
5 Chapter5
Your Location: Home Page  >  [3] Interactive web pages using JavaScript (on condition)  >  [Session11] JavaScript 1 (Interactive page)  >  Chapter3  >  3.3.2 Application of Handling (2) -- Event and Event Handler
3. Application of Handling (2) -- Event and Event Handler
[The purpose of this section]
Learn the meaning of “event”, and how an “event handler” works.

Event

Generally, when some action occurs against some object; for example, a mouse being clicked, the signal issued as the result is called an event.

As an example, when the “Back” button in a Web browser is clicked, we call this “an event of the mouse being clicked over the Back button occurs.”

(Note) Consider “an event occurs” as an abstract signal that such an event has occurred rather than the real electric signal being issued.

Only, “an event occurs,” however, does not generally create any change on the screen (or any operation) of the PC. This is because a PC is generally designed to ignore these events. There are so many such events always occurring around a PC that responding to all of them will stop the PC from doing anything meaningful.

Event Handler

To make good use of a PC, you just need to let it ignore everything once, and only let it handle the necessary events in the predetermined way. The one (program) that “handles the necessary events in the predetermined way” is called an event handler. Therefore, the event handler will

  1. monitor the occurrence of particular events, and
  2. execute (or request to execute) the predetermined handling when such event occurs.

Let’s see how the event handler works in the actual example. In the figure below, an event handler named OnMouseOver is monitoring an event in which a mouse pointer enters the fish picture area in a Web browser.

未だ来ない?

When the event occurs (the mouse pointer comes to fish area), a handling of “displaying bone picture instead of fish” is requested to the PC (actually to the Web browser).

来た!

Then the handling is executed, and the fish picture turns to the bone picture.

骨の絵に!

There are many event handlers available in HTML, but if you know the following three, you will be able to handle most of the events related to mouse operations.

Event handler name Handling contents/th>
onClick When the mouse is clicked at a particular area, the instructed handling is executed.
onMouseOver When the mouse pointer enters the particular area, the instructed handling is executed.
onMouseOut When the mouse pointer leaves the particular area, the instructed handling is executed.

Web browsers monitor various kinds of events. When, for example an event is detected that the “Back” button area is clicked, handling such as going back to the previous page will be executed.

Copyright (C) Kenichi Sugitani, Hideki Matsuda, Chisato Noguchi and Fumiko Ryu 2005-2006, All Rights Reserved