Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

change | onchange event

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

HTML 4.01 Specification, Section 18.2.3

 

Syntax

HTML Attribute <element onchange = "handler(event)">
Event Property object.onchange = handler;
attachEvent Method object.attachEvent("onchange", handler)
addEventListener Method object.addEventListener("change", handler, useCapture)

 

Event information

SynchronousNo
BubblesNo
CancelableYes

 

Event handler parameters

pEvtObj [in]

Type: IHTMLEventObj

Standards information

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 programmatically.

Changed text selection is committed.

To invoke this event, do one of the following:

  • 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.

The pEvtObj parameter is required for the following interfaces:

Examples

This example uses the onchange event to retrieve the selected option of a select object.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/onchangeEX.htm


<!DOCTYPE html>
<html>

<head>
  <title>onchange Event Sample</title>
</head>

<body>
  <h1>onchange Event Sample</h1>
  <form>
    <p>Select a different option in the drop-down listbox to trigger the <strong>onchange</strong> event.</p>
		  <select name="selTest" onchange="alert('Index: ' + this.selectedIndex + '\nValue: ' + this.options[this.selectedIndex].value)">
      <option value="Books">Books</option>
      <option value="Clothing">Clothing</option>
      <option value="Housewares">Housewares</option>
    </select>
  </form>
</body>

</html>

See also

a
abbr
acronym
address
applet
area
audio
b
base
baseFont
bdo
bgSound
big
blockQuote
body
br
button
canvas
caption
center
cite
code
col
colGroup
comment
custom
dd
del
dfn
dir
div
dl
document
dt
em
embed
fieldSet
font
form
frame
frameSet
head
hn
hr
html
i
iframe
img
input type=button
input type=checkbox
input type=email
input type=file
input type=hidden
input type=image
input type=number
input type=password
input type=radio
input type=range
input type=reset
input type=search
input type=submit
input type=tel
input type=text
input type=url
ins
isIndex
kbd
label
legend
li
link
listing
map
marquee
media
menu
meta
nextID
noBR
noFrames
noScript
object
ol
optGroup
option
p
param
plainText
pre
q
rt
ruby
s
samp
script
select
small
source
span
strike
strong
style
sub
sup
table
tBody
td
textArea
tFoot
th
tHead
title
tr
tt
u
ul
var
video
wbr
window
xmp
onkeypress

 

 

Show:
© 2014 Microsoft