www.fgks.org   »   [go: up one dir, main page]

Click to Rate and Give Feedback
 onchange Event
onchange Event

Fires when the contents of the object or selection have changed.

Syntax

Inline HTML<ELEMENT onchange = "handler" ... > All platforms
Event propertyobject.onchange = handlerJScript only
object.onchange = GetRef("handler")Visual Basic Scripting Edition (VBScript) 5.0 or later only
Named script <SCRIPT FOR = object EVENT = onchange> Internet Explorer only

Event Information

BubblesNo
CancelsYes
To invoke
  • Choose a different option in a select object using mouse or keyboard navigation.
  • Alter text in the text area and then navigate out of the object.
Default action Changed text selection is committed.

Event Object Properties

Although event handlers in the DHTML Object Model do not receive parameters directly, a handler can query the event object for the following event properties.

Available Properties

altKey Sets or retrieves a value that indicates the state of the ALT key.
altLeft Sets or retrieves a value that indicates the state of the left ALT key.
clientX Sets or retrieves the x-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
clientY Sets or retrieves the y-coordinate of the mouse pointer's position relative to the client area of the window, excluding window decorations and scroll bars.
ctrlLeft Sets or retrieves the state of the left CTRL key.
offsetX Sets or retrieves the x-coordinate of the mouse pointer's position relative to the object firing the event.
offsetY Sets or retrieves the y-coordinate of the mouse pointer's position relative to the object firing the event.
returnValue Sets or retrieves the return value from the event.
screenX Sets or retrieves the x-coordinate of the mouse pointer's position relative to the user's screen.
screenY Sets or retrieves the y-coordinate of the mouse pointer's position relative to the user's screen.
shiftLeft Retrieves the state of the left SHIFT key.
srcElement Sets or retrieves the object that fired the event.
type Sets or retrieves the event name from the event object.
x Sets or retrieves the x-coordinate, in pixels, of the mouse pointer's position relative to a relatively positioned parent element.
y Sets or retrieves the y-coordinate, in pixels, of the mouse pointer's position relative to a relatively positioned parent element.

Remarks

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.

The onchange event does not fire when the selected option of the select object is changed programatically.

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" >
	<option value="Books">Books</option>
	<option value="Clothing">Clothing</option>
	<option value="Housewares">Housewares</option>
	</select> </p>
</form>

</body>
This feature requires Microsoft® Internet Explorer 4.0 or later. Click the following icon to install the latest version. Then reload this page to view the sample.

Standards Information

This event is defined in HTML 4.0 World Wide Web link.

Applies To

INPUT type=text, SELECT, TEXTAREA

See Also

onkeypress
Tags What's this?: Add a tag
Community Content
 
Add Community Content
Fires late on a readio/checkbox button      stuartg2k ... John Sudds - MSFT   |   Edit   |  
If you use onchange on a radio or checkbox button, the onchange event will not fire until you "blur" the element.

[jsudds] That is correct. If you wish to automate some part of your UI based on instant feedback from a checkbox, you'll want to use the onclick event instead.
Tags What's this?: dhtml (x) Add a tag
onEvent malfunctions in IE7 if they are added to an element via the setAttribute() function.      urMum   |   Edit   |  
onEvent handlers will not work in Internet Explorer 7 (and below?) if they are added to an element via the setAttribute() function. Instead the element.innerHTML must be used.
Tags What's this?: Add a tag
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker
DCSIMG