onkeypress
Events Reference

onkeypress

Description

Fires when a user presses a key.

Return Value

Returns a number specifying the Unicode value of the key that was pressed.

Remarks

The return value can be used to override the keycode value. This event will bubble. Events that bubble can be handled on any parent element of the object that fired the event.

To cancel the keystroke, use the following code in the onkeypress event:

event.returnValue=false;

Applies To

A, ACRONYM, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DEL, DFN, DIR, DIV, DT, EM, FIELDSET, FONT, FORM, H1, H2, H3, H4, H5, H6, HR, I, IMG, INPUT, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OBJECT, OL, P, PLAINTEXT, PRE, Q, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, document

See Also

onchange


onkeyup

Description

Fires when the user releases a key.

Return Value

Returns a number specifying the keycode of the key released.

Remarks

The return value can be used to override the keycode. This event will bubble. Events that bubble can be handled on any parent element of the object that fired the event.

Applies To

A, ACRONYM, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DEL, DFN, DIR, DIV, DT, EM, FIELDSET, FONT, FORM, H1, H2, H3, H4, H5, H6, HR, I, IMG, INPUT, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OBJECT, OL, P, PLAINTEXT, PRE, Q, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, document


onload

Description

Fires immediately after the browser loads the given object.

Remarks

The browser loads applications, embedded objects, and images as soon as it encounters the APPLET, EMBED, and IMG elements during parsing. This means that the onload event for these objects occurs before the browser parses any subsequent elements. To ensure that an event handler receives the onload event for these elements, you must place the SCRIPT element that defines the event handler before the element and use the onload attribute in the element to set the handler.

The onload attribute of the BODY element sets an onload event handler for the window. Setting an onload event handler for the window object by any other means will override the handler set using the onload attribute if the handlers are in the same script language.

Examples

The following JScript example is an onload event handler for the window.

<SCRIPT FOR=window EVENT=onload LANGUAGE="JScript">
window.status = "Page is loaded!";
</SCRIPT>

The following JScript example sets an onload event handler for an IMG element. The handler uses the event object to retrieve the URL of the image.

<SCRIPT LANGUAGE="JScript">
function imageLoaded()
{
    window.status = "Image \"" + window.event.srcElement.src + "\" is loaded";
}
</SCRIPT>
<IMG SRC="sample.gif" onclick="imageLoaded()">

This event will not bubble. Events that do not bubble can only be handled on the individual object that fired the event.

Applies To

APPLET, BODY, EMBED, FRAMESET, IMG, LINK, SCRIPT, STYLE, window


onmousedown

Description

Fires when the user presses a button on a pointer device, such as the mouse.

Remarks

The event ordering for mouse-related events is:

  1. onmousedown
  2. onmouseup
  3. onclick
  4. ondblclick
  5. onmouseup

This event will bubble. Events that bubble can be handled on any parent element of the object that fired the event.

Applies To

A, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, H1, H2, H3, H4, H5, H6, HR, I, IMG, INPUT, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, document

See Also

ondblclick, onmousemove, onmouseup


onmousemove

Description

Fires when the user moves the mouse.

Remarks

The event ordering for moving the mouse is:

  1. onmouseover
  2. onmousemove
  3. onmouseout

This event will bubble. Events that bubble can be handled on any parent element of the object that fired the event.

Applies To

A, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, H1, H2, H3, H4, H5, H6, HR, I, IMG, INPUT, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, document

See Also

onmousedown, onmouseup


onmouseout

Description

Fires when the user moves the mouse pointer out of an element.

Remarks

When the user moves the mouse pointer into an element, one onmouseover event occurs, followed by one or more onmousemove events as the user moves the pointer within the element, and finally one onmouseout event when the user moves the pointer out of the element. This event will bubble. Events that bubble can be handled on any parent element of the object that fired the event.

Examples

The following JScript example sets the onmouseout event handler for an element having the identifier "para_1". The handler changes the color of the text in the element when the mouse pointer leaves the element.

<SCRIPT FOR=para_1 EVENT=onmouseout LANGUAGE="JScript">
var el = window.event.srcElement;
for ( ; el.id != "para_1"; el = el.parentElement);
el.style.color = "silver";
</SCRIPT>

The following JScript example sets the onmouseout event handler for an IMG element. The handler changes the image source file for the element when the mouse pointer leaves the element.

<IMG SRC="inactive.gif" onmouseover="flipImage('active.gif')" onmouseout="flipImage('inactive.gif')">
    .
    .
    .
<SCRIPT LANGUAGE="JScript">
function flipImage(url)
{
    if (window.event.srcElement.tagName == "IMG" ) {
        window.event.srcElement.src = url;
    }
}
</SCRIPT>

Applies To

A, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, H1, H2, H3, H4, H5, H6, HR, I, IMG, INPUT, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, document


onmouseover

Description

Fires when the user moves the mouse pointer into an element. The event occurs when the pointer first enters the element and does not repeat unless the user moves the pointer out of the element and then back into it.

Remarks

When the user moves the mouse pointer into an element, one onmouseover event occurs, followed by one or more onmousemove events as the user moves the pointer within the element, and finally one onmouseout event when the user moves the pointer out of the element. This event will bubble. Events that bubble can be handled on any parent element of the object that fired the event.

Examples

The following JScript example sets the onmouseover event handler for an element having the identifier "para_1". The handler changes the color of the text in the element when the mouse pointer enters the element.

<SCRIPT FOR=para_1 EVENT=onmouseover LANGUAGE="JScript">
var el = window.event.srcElement;
for ( ; el.id != "para_1"; el = el.parentElement);
el.style.color = "black";
</SCRIPT>

The following JScript example sets the onmouseover event handler for an IMG element. The handler changes the image source file for the element when the mouse pointer enters the element.

<IMG SRC="inactive.gif" onmouseover="flipImage('active.gif')" onmouseout="flipImage('inactive.gif')">
    .
    .
    .
<SCRIPT LANGUAGE="JScript">
function flipImage(url)
{
    if (window.event.srcElement.tagName == "IMG" ) {
        window.event.srcElement.src = url;
    }
}
</SCRIPT>

Applies To

A, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, H1, H2, H3, H4, H5, H6, HR, I, IMG, INPUT, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, document


onmouseup

Description

Fires when the user releases a mouse button.

Remarks

This event will bubble. Events that bubble can be handled on any parent element of the object that fired the event.

Applies To

A, ADDRESS, APPLET, AREA, B, BIG, BLOCKQUOTE, BODY, BUTTON, CAPTION, CENTER, CITE, CODE, DD, DFN, DIR, DIV, DL, DT, EM, EMBED, FIELDSET, FONT, FORM, H1, H2, H3, H4, H5, H6, HR, I, IMG, INPUT, KBD, LABEL, LEGEND, LI, LISTING, MAP, MARQUEE, MENU, OL, P, PLAINTEXT, PRE, S, SAMP, SELECT, SMALL, SPAN, STRIKE, STRONG, SUB, SUP, TABLE, TBODY, TD, TEXTAREA, TFOOT, TH, THEAD, TR, TT, U, UL, VAR, XMP, document

See Also

ondblclick, onmousedown, onmousemove


onreadystatechange

Description

Fires whenever the ready state for the object has changed.

Remarks

Each object can choose to expose which set of ready states it is exposing. This event should be fired whenever the ready state is changed.

When an element changes to the loaded state, this event fires immediately before the firing of the load event. This event will not bubble. Events that do not bubble can only be handled on the individual object that fired the event.

Applies To

APPLET, EMBED, FRAME, FRAMESET, IFRAME, IMG, LINK, OBJECT, SCRIPT, STYLE, document

See Also

onload, readyState


onreset

Description

Fires when a user resets a form (clicks a Reset button). The onreset event handler executes code when a reset event occurs.

Remarks

This event will not bubble. Events that do not bubble can only be handled on the individual object that fired the event.

Applies To

FORM


onresize

Description

Fires at the beginning of a resize operation.

Remarks

This event will not bubble. Events that do not bubble can only be handled on the individual object that fired the event. This event will not fire for files with embedded controls.

Applies To

APPLET, BUTTON, CAPTION, DIV, EMBED, FRAMESET, HR, IMG, MARQUEE, SELECT, TABLE, TD, TR, TEXTAREA, window

© 1997 Microsoft Corporation. All rights reserved. Terms of Use.