Skip to content Skip to sidebar Skip to footer

In What Authorative Specification Is The Onchange Event Exhaustively Defined?

I was slightly surprised to find out that the onChange event in an html document is fired on a text input or textarea not at the very moment when its value actually changes, but on

Solution 1:

It's briefly mentioned in the Intrinsic events section of the W3C 4.01 specification:

"The onchange event occurs when a control loses the input focus and its value has been modified since gaining focus".

It's also mentioned a little more extensively on MSDN:

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

Finally, on the MDN:

Depending on the kind of the form element being changed and the way the user interacts with the element, the change event fires at a different moment:

  • When the element is activated (by clicking or using the keyboard) for <input type="radio"> and <input type="checkbox">;
  • When the user commits the change explicitly (e.g. by selecting a value from a <select>'s dropdown with a mouse click, by selecting a date from a date pickier for <input type="date">, by selecting a file in the file picker for <input type="file">, etc.);
  • When the element loses focus after its value was changed, but not committed (e.g. after editing the value of <textarea> or <input type="text">).

Another potentially useful link - WhatWg - specification - change event.

Post a Comment for "In What Authorative Specification Is The Onchange Event Exhaustively Defined?"