Fires when the contents of the object or selection have changed.
Syntax
Inline HTML <ELEMENT onchange = "handler" ... > All platforms Event property object.onchange = handler JScript (compatible with ECMA 262 language specification) only Named script <SCRIPT FOR = object EVENT = onchange> Internet Explorer only
Remarks
Bubbles No Cancels Yes To invoke Default action Changed text selection is committed. This event is fired when the contents are committed and not while the value is changing. For example, on a text box, this event is not fired while the user is typing, but rather when the user commits the change by leaving the text box that has focus. In addition, this event is executed before the code specified by onblur when the control is also losing the focus.
On the SELECT object, this event does not fire programmatically when the SELECTED attribute is changed from one OPTION to another.
Event Object Properties
Although event handlers in the document object model do not receive parameters directly, the handler can query the event object for data.
clientX Retrieves the x-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars. clientY Retrieves the y-coordinate of the mouse cursor relative to the client area of the window, excluding window decorations or scroll bars. offsetX Retrieves the horizontal coordinate of the mouse's position relative to the object firing the event. offsetY Retrieves the vertical coordinate of the mouse's position relative to the object firing the event. returnValue Sets or retrieves the return value from the event. screenX Retrieves the horizontal position of the mouse, in pixels, relative to the user's screen. screenY Retrieves the vertical position of the mouse, in pixels, relative to the user's screen. srcElement Retrieves the object that fired the event. type Retrieves the event name from the event object. x Retrieves the x-coordinate of the mouse cursor relative to the parent element. y Retrieves the y-coordinate of the mouse cursor relative to the parent element.
Example
This example uses the onchange event to retrieve the selected option of a SELECT object.
<BODY> <FORM> <P>Select a different option in the drop-down list box to trigger the onchange event. <SELECT NAME=selTest onchange="alert('Index: ' + this.selectedIndex + '\nValue: ' + this.options[this.selectedIndex].value)"> <OPTION VALUE="Books">Books <OPTION VALUE="Clothing">Clothing <OPTION VALUE="Housewares">Housewares </SELECT> </FORM> </BODY>
Applies To
INPUT TYPE=text, SELECT, TEXTAREA
See Also