W3C home > Mailing lists > Public > whatwg@whatwg.org > October 2008

[whatwg] Web Forms: change event

From: Garrett Smith <dhtmlkitchen@gmail.com>
Date: Wed, 29 Oct 2008 21:32:49 -0700
Message-ID: <490938F1.7030006@gmail.com>
Ian Hickson wrote:
> On Wed, 6 Jun 2007, Sander wrote:
>> The specs say that for <select> "...the change event shall be fired when 
>> the selection is completed...". Does this mean that, when using a 
>> keyboard for navigation, the change event is fired when the user hits 
>> 'enter' or when she navigates from one option to another? I assume it's 
>> the former, but I just to be sure as selectboxes with change event 
>> handlers are often (ab)used for navigation purposes. So, can anyone 
>> confirm my assumption? Thanks.
> 
The HTML 4 specification[1] says:

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

A "test case"[2] I found does expects that onchange fires when the 
select has been changed and while it still has focus.

| Procedure
|   1. Using the keyboard or an assistive technology that emulates the
| keyboard, move focus to the select control.
|   2. Using the keyboard or an assistive technology that emulates the
| keyboard, select a value from the menu to trigger the onChange event.

[example]

| Expected results
|
|   1. A star colored according to the select option value appears when
| the onchange event is triggered.

Firing onchange before the select loses focus does not follow the HTML 
specification but is more useful and is what browsers mostly do.

Often, a select is used to trigger another action, such as showing more 
fields in a form. The user chooses an option and, based on the 
selection, a section of the form is shown. If the change event does not 
fire when the item is chosen, the callback will not be called and the 
user will not see the event until he changes focus by tabbing or 
clicking away.

Instead, the chagne event should (ideally) fire when a different option 
has been selected.


> Depends on the platform. 

Yep. Select-multiple adds one more variant.

> I've used different wording in HTML5, let me know 
> if it's confusing still (it probably is), and what it should say instead.
> 

Link or text?

It would be useful to have x-browser way to get a select change event.

The change does not bubble in all browsers.

Depending on the implementation, a change event may or may not fire on:
  * alphanumeric key press (selects an element)
  * up/down arrow key press (selects an element)
  * select via enter after arrow key press

It is generally desirable to have a select fire the event when the value 
has changed, even if it still has focus.

Garrett

[1]http://www.w3.org/WAI/UA/TS/html401/cp0102/0102-ONCHANGE-SELECT.html
[2]http://www.w3.org/TR/html401/interact/scripts.html#adef-onchange
-- 
comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
Received on Wednesday, 29 October 2008 21:32:49 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:59:06 UTC