DOM Event Handling



index
Disabled back button Next Section
printable version

Section 1: Events and Event Handling

An event is a notification that something specific has occurred, triggered by either the browser or a user action.

An event handler is a script that is implicitly executed in response to an event.

The process of connecting an event handler to an event is called registration.


Note: Don't use document.write in an event handler, because the output may overwrite the display.

Event Tag Attribute
blur onblur
change onchange
click onclick
focus onfocus
load onload
mousedown onmousedown
mousemove onmousemove
mouseout onmouseout
mouseover onmouseover
mouseup onmouseup
select onselect
submit onsubmit
unload onunload

A text element gets focus in three ways:

  1. When the user puts the mouse cursor over it and presses the left button.
  2. When the user tabs to the element.
  3. By executing the focus method.

Event handlers can be registered:

  1. By assigning the event handler script to an event tag attribute:

    <input type = "button" id = "myButton" onclick = "alert('Mouse click!');" />

  2. By assigning a function to an event tag attribute:

    <input type = "button" id = "myButton" onclick = "myHandler();" />

Section 2: Handling Events from Button Elements

Plain buttons

Radio buttons

Section 3: Handling Events from Textbox and Password Elements
Section 4: Resources