XHTML Events

When we visit a website, we do several things like click on text, images and hyperlinks 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. In XHTML Event handler, we can associate event handlers to a tag by specifying attributes. These attributes are onload, onclick, onsubmit etc can be apply to the form and button tags.

The <body> and <frameset> Level Events

In <body> and <frameset> level events, two attributes are used to trigger any JavaScript or VBScript code, when any event occurs at document level.
Attribute Value Description
Onload Event handler It calls event handler when a XHTML document loads.
Onunload Event handler It calls event handler when a XHTML document unloads.

Note: Here, The Event handler refers to any function or piece of Event handler of VBScript or JavaScript.

The <form> Level Events

In <form> level Events, six attributes are used to trigger any JavaScript or VBScript code when any event occurs at form level.
Attribute Value Description
Onchange Event handler Event handler executes when the element Changes.
Onsubmit Event handler Event handler executes when the form is submitted.
Onreset Event handler Event handler executes when the form is reset.
Onselect Event handler Event handler executes when the element is selected.
Onblur Event handler Event handler executes when the element loses focus.
Onfocus Event handler Event handler runs when the element gets focus.

Keyboard Events

In Keyboard Events, three events are generated. Keyboard events are not valid in base, bdo, br, frameset, frame, head, html, meta, iframe, param, script, style, and title elements.
Attribute Value Description
Onkeydown Event handler Event handler executes on key press.
Onkeypress Event handler Event handler executes on key press and release.
Onkeyup Event handler Event handler executes on key release.

Mouse Events

In Mouse Events, seven events are generated. Mouse events are not valid in base, bdo, br, frameset, frame, head, html, meta, iframe, param, script, style, and title elements.
Attribute Value Description
Onclick Event handler Event handler executes on a mouse click.
Ondblclick Event handler Event handler executes on a mouse-double click.
Onmousedown Event handler Event handler executes when a mouse button is pressed.
Onmousemove Event handler Event handler executes when mouse pointer is moved.
Onmouseout Event handler Event handler executes when mouse pointer moves out of an element.
Onmouseover Event handler Event handler executes when mouse pointer moves over an element.
Onmouseup Event handler Event handler executes when mouse button is released.