You can set up your document to run a script when various events occur, such as mouse clicks or keys struck on the keyboard. To do this, attach one of these intrinsic event attributes to an element; the value of the attribute is an expression in your scripting language that can handle that event.
To use these attributes, you must declare the scripting
language in a meta element inside the page's
head element. Here is the general form of this
declaration:
<meta http=equiv='Content-Script-Type' content='T'/>
where is the
MIME type of the scripting language. For example, the MIME
type of JavaScript is Tcontent='text/javascript'. See Section 6.7, “MIME types: Defining a resource's format”.
Here are the intrinsic event attributes, and the things that can happen to an element with that attribute that will cause the script to be run.
onblur |
When an element loses focus. See the onfocus event below for a discussion of
focus. We're not talking about actual blurriness
here; it's just a play on words. If your eyes lose
focus, what you see is blurry, right?
|
onchange |
When a control on a form changes its value. To be
precise, this happens only when the user moves
focus onto the control, changes the value of an
input, textarea, or
select element, and then moves focus
out of the control. See Section 14, “Forms: The form element”.
|
onclick | When the user clicks the mouse button over the element. |
ondblclick | When the user double-clicks the mouse on the element. |
onfocus |
At any given time, some element is said to have
focus; this means that any keyboard input from the
user is sent to that element. The onfocus event on an element happens when
the focus is moved to that element. This can
happen due to use of the tab
key, or because the user clicked on it.
|
onkeydown |
When a user presses a key; applies to the element
with focus. See onfocus for a
discussion of focus.
|
onkeypress |
When a user presses and then releases a key on the
keyboard; applies to the element that has focus.
See onfocus, above, for a discussion
of focus.
|
onkeyup |
When a user releases a key after pressing it.
Compare onkeydown and onkeypress.
|
onload |
When a body element has finished
loading.
|
onmousedown | When the mouse button is depressed over the element. |
onmousemove |
When the mouse is moved within an element. Not
every position will be reported; the faster the
mouse is moved, the fewer onmousemove events will be generated.
|
onmouseout | When the mouse is moved out of an element. |
onmouseover | When the mouse is moved onto the element. |
onmouseup | When the mouse button is released over the element. |
onreset |
When a user clicks on the reset button of a form;
see Section 14, “Forms: The form element”.
|
onselect |
When a user selects some text, as in a textarea element or an input text field. See Section 14, “Forms: The form element”.
|
onsubmit |
When a user submits a form; see Section 14, “Forms: The form element”.
|
onunload |
When a body element has been removed
from a browser window.
|