When users visit a website, they do things such as 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.
There are only two attributes which can be used to trigger any JavaScript or VBScript code, when any event occurs at document level.
Attribute | Value | Description |
---|---|---|
onload | Script | Script runs when a XHTML document loads. |
onunload | Script | Script runs when a XHTML document unloads. |
Note − Here, the script refers to any function or piece of code of VBScript or JavaScript.
There are following six attributes which can be used to trigger any JavaScript or VBScript code when any event occurs at form level.
Attribute | Value | Description |
---|---|---|
onchange | Script | Script executes when the element changes. |
onsubmit | Script | Script executes when the form is submitted. |
onreset | Script | Script executes when the form is reset. |
onselect | Script | Script executes when the element is selected. |
onblur | Script | Script executes when the element loses focus. |
onfocus | Script | Script runs when the element gets focus. |
The following three events are generated by keyboard. These events are not valid in base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.
Attribute | Value | Description |
---|---|---|
onkeydown | Script | Script executes on key press. |
onkeypress | Script | Script executes on key press and release. |
onkeyup | Script | Script executes key release. |
The following seven events are generated by mouse 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.
Attribute | Value | Description |
---|---|---|
onclick | Script | Script executes on a mouse click. |
ondblclick | Script | Script executes on a mouse double-click. |
onmousedown | Script | Script executes when mouse button is pressed. |
onmousemove | Script | Script executes when mouse pointer moves. |
onmouseout | Script | Script executes when mouse pointer moves out of an element. |
onmouseover | Script | Script executes when mouse pointer moves over an element. |
onmouseup | Script | Script executes when mouse button is released. |