XHTML Events

 

When you go to a website, you can click on text, images, and links, move your mouse over things, and so on. These are examples of events in JavaScript.

We can write our event handlers in either JavaScript or VBScript, and we can use the value of the event tag attribute to point to these event handlers. The events in XHTML 1.0 are the same as those in the HTML 4.01 specification.

The <body> and <frameset> Level Events

There are only two attributes that can be used to run any JavaScript or VBScript code when a document-level event happens.

AttributeValueDescription
onloadScriptWhen an XHTML file loads, a script runs.
onunloadScript
When an XHTML document stops loading, a script is run.

The <form> Level Events

There are six attributes that happen whenever any event at the form level happens.

AttributeValueDescription
onchangeScriptWhen the element changes, the code is run.
onsubmitScript
It is carried out when the form is sent.

onresetScriptWhenever the form is cleared, it is run.
onselectScriptWhenever the element is chosen, the code is run.
onblurScriptWhen the element loses attention, it is activated.
onfocusScriptWhen the element receives focus, the code is run.

Keyboard Events

There are three things that can happen when you use the keyboard. The keyboard events are not allowed in the base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.

AttributeValueDescription
onkeydownScriptOnce the user presses and releases the corresponding key on the keyboard, this action is carried out.
onkeypressScriptWhen the finger is lifted off the keyboard, something occurs.
onkeyupScriptThis is executed when the user release the keyboard button.

Mouse Events

There are some mouse-driven events that run when the mouse touches an HTML tag. These events are not allowed in the base, bdo, br, frame, frameset, head, html, iframe, meta, param, script, style, and title elements.

AttributeValueDescription
onclickScriptA single click of the mouse to execute code.
ondblclickScriptA mouse double-click to execute code..
onmousedownScriptwhen mouse button is pressed to execute code..
onmousemoveScriptWhen mouse pointer moves to execute code..
onmouseoutScriptWhen mouse pointer moves out of an element to execute code..
onmouseoverScriptWhen mouse pointer moves over an element to execute code..
onmouseupScriptWhen mouse button is released to execute code..