JavaScript: Events

Reading HTML 9.14-9.33

Events are things that happen while using the computer. Every mouse move or click, every keypress is an event. Some are combinations. Moving the mouse over the little x in the corner of the window is a mouseover, clicking it is a mouse down, mouse up event and a click event. As the window closes, that is a window close event. Not all events apply to all things in the browser. Only the window has an onClose event. For the events that are relevant to an object on the page, you can connect JavaScript code to it by using the event name as an attribute on the tag that created the object. For example, the onLoad event occurs when the page is loaded by the browser. You can put this on the body tag like this.

<body onLoad="loader();">

Here is a table of mouse events. This and the following tables of events are taken from http://www.webdevelopersjournal.com/articles/jsevents1/jsevents1.html

Mouse Event Description
onmousedown A mouse button has been pressed
onmousemove The mouse has been moved
onmouseout The mouse pointer has left an element
onmouseover The mouse pointer has entered an element
onmouseup A mouse button has been released
onclick A mouse button has been clicked
ondblclick A mouse button has been double-clicked (clicked twice rapidly)

The keyboard also creates events

Keyboard Event Description
onkeydown A key has been pressed
onkeypress onkeydown followed by onkeyup
onkeyup A key has been released

There are a number of events that are more indirect.

Event Description
onblur An element loses focus
onerror An error occurs
onfocus An element gains focus
onload The document has completely loaded
onreset A form reset command is issued
onscroll The document is scrolled
onselect The selection of element has changed
onsubmit A form submit command is issued