Skip to main content

XHTML Events

When you visit a website, you do things like click on text, images and hyperlinks, hover-over things, etc. These are examples of what JavaScript calls events.

We can write our event handlers in JavaScript or VBScript and can specify these event handlers as a value of event tag attribute.

The XHTML 1.0 has a similar set of events which is available in HTML 4.01 specification.

The <body> and <frameset> Level Events

There are only two attributes which are used to trigger any JavaScript or VBScript code, when any event occurs at document level.

AttributeValueDescription
onloadScriptScript runs when a XHTML document loads.
onunloadScriptScript runs when a XHTML document unloads.

The <form> Level Events

There are six attributes which are triggered when any event occurs at form level.

AttributeValueDescription
onchangeScriptIt is executed when the element changes.
onsubmitScriptIt is executed when the form is submitted.
onresetScriptIt is executed when the form is reset.
onselectScriptIt is executed when the element is selected.
onblurScriptIt is executed when the element loses focus.
onfocusScriptIt is executed when the element gets focus.

Keyboard Events

There are three events which are generated by keyboard. The keyboard events are not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.

AttributeValueDescription
onkeydownScriptThis is executed when the user press the keyboard button.
onkeypressScriptThis is executed when the user press and release the keyboard button.
onkeyupScriptThis is executed when the user release the keyboard button.

Mouse Events

There are some mouse generated events which executes when it comes in contact with any HTML tag. These events are not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.

AttributeValueDescription
onclickScriptIt is executed on a mouse click.
ondblclickScriptIt is executed on a mouse double-click.
onmousedownScriptIt is executed when mouse button is pressed.
onmousemoveScriptIt is executed when mouse pointer moves.
onmouseoutScriptIt is executed when mouse pointer moves out of an element.
onmouseoverScriptIt is executed when mouse pointer moves over an element.
onmouseupScriptIt is executed when mouse button is released.