asp.net.ph

onchange Event

DHTML Events


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

Syntax


Inline HTML <element onchange = "handler" ... > All platforms
Event property object.onchange = handler ECMA-262 Language Specification
Named script <script FOR=object EVENT=onchange> Internet Explorer® only

Remarks


Bubbles No
Cancels Yes
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.

A change event occurs when a control loses the input focus and its value has been modified since gaining focus. This event is valid for INPUT type=text, SELECT, TEXTAREA element.

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

While event handlers in the Document Object Model do not receive parameters directly, the handler can query the event object for data.

Event Object Properties


Example

The example below shows how the onchange event works on the SELECT object.

Sample Code

The following example shows use of the onchange event to trigger the function checkNum that checks for a range of values. If the value of the INPUT element is not within the valid range, the focus and select methods are used to set focus back to and highlight the INPUT. Otherwise, it calls the function thanks.

Sample Code

<input name="num"
  onchange="if (!checkNum(this.value, 1, 10)) 
    {this.focus();this.select();} else {thanks()}"
    value="0">
Applies To

HTMLAREA, INPUT type=text, SELECT, TEXTAREA

See Also

onkeypress




Contents
HTML Elements
HTML Element Attributes
CSS Attributes
DOM Objects
DOM Object Properties
DOM Events Reference
DOM Methods Reference
DOM Collections Reference
 

Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph