Home ยป XHTML Events

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.
onkeypressScript This is executed when the user press and release the keyboard button.
onkeyupScript This 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.
ondblclickScript It is executed on a mouse double-click.
onmousedownScript It is executed when mouse button is pressed.
onmousemoveScript It is executed when mouse pointer moves.
onmouseoutScript It is executed when mouse pointer moves out of an element.
onmouseoverScript It is executed when mouse pointer moves over an element.
onmouseupScript It is executed when mouse button is released.
Next TopicHXHTML Doctypes

You may also like