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.
The <body> and <frameset> Level Events
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.
The <form> Level Events
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 | It is executed when the element changes. |
onsubmit | Script | It is executed when the form is submitted. |
onreset | Script | It is executed when the form is reset. |
onselect | Script | It is executed when the element is selected. |
onblur | Script | It is executed when the element loses focus. |
onfocus | Script | It is executed when the element gets focus. |
Keyboard Events
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 | This is executed when the user press the keyboard button. | |
onkeypress | Script | This is executed when the user press and release the keyboard button. | |
onkeyup | Script | This is executed when the user release the keyboard button. |
Other Events
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 | It is executed on a mouse click. |
ondblclick | Script | It is executed on a mouse double-click. |
onmousedown | Script | It is executed when mouse button is pressed. |
onmousemove | Script | It is executed when mouse pointer moves. |
onmouseout | Script | It is executed when mouse pointer moves out of an element. |
onmouseover | Script | It is executed when mouse pointer moves over an element. |
onmouseup | Script | It is executed when mouse button is released. |