onchange triggered before checkbox/radio loses focus instead of after




DOM: Events
14 years ago
7 years ago


(Reporter: Kevin Ar18, Unassigned)



Firefox Tracking Flags

(Not tracked)



(1 attachment, 1 obsolete attachment)

2.40 KB, text/html


14 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6a) Gecko/20031002 Firebird/0.7+
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6a) Gecko/20031002 Firebird/0.7+

According to the W3 specs, onchange is supposed to be triggered after the
"control" loses focus.  Currently, Mozilla triggers onchange (in a checkbox)
before it loses focus.

The exact wording of the spec is as follows:
The onchange event occurs when a control loses the input focus and its value has
been modified since gaining focus. This attribute applies to the following
elements: INPUT, SELECT, and TEXTAREA.

Reproducible: Always

Steps to Reproduce:
0. Imagine you have the following code on a page: <input type="checkbox"
onChange="alert('checkbox 1 - onChange')">
Basically it pops up an alert whenever onChange is triggered.

You may reproduce this issue with the keyboard or mouse.
1. Using your mouse, click on the checkbox.
2. Release your mouse button

alternatively, using your keyboard
1. tab over to the checkbox, so that is has focus
2. press the spacebar down to change it's value
3. release the spacebar.
Actual Results:  
The actual results of both instances is that the onchange event is triggered.

Expected Results:  
Instead, the onchange event should wait until the checkbox loses focus before
being triggered.

I will add that I believe that this was a poor design choice by W3C.  I do not
think they should have made it wait until focus is lost till onchange gets
triggered.  However it is the spec, nonetheless.  Thus, I have filed it as a bug
on the part of Mozilla.

Comment 1

14 years ago
Created attachment 137310 [details]
Test case

Comment 2

14 years ago
Reluctantly confirming. Mozilla's behavior is what should be in the spec, and
the specified behavior is next to useless. Nonethless, Mozilla does not comply
with the spec. Since other browsers (notably IE) do, there's probably not much
hope for getting the spec changed.

I can't imagine a good solution to this problem. If the behavior is left as it
is, there may be scripts that rely on the specified behavior that won't work
with Mozilla. On the other hand, I *know* there are cases where Mozilla's
behavior is more useful, and implementing the specified behavior will remove
that behavior. There may already be scripts relying on it, accidentally or by
Ever confirmed: true

Comment 3

14 years ago
Created attachment 137311 [details]
Updated test case

The original test case had a minor error.


14 years ago
Attachment #137310 - Attachment is obsolete: true
The Web Forms 2.0 spec adds oninput which would be triggered when the checkbox 
state changes, which would cope with this case I think.

Comment 5

14 years ago
Thanks for the info.
Here's the URL I found on that:

Here's something interesting I noted about it:
Status of this document
This is a work in progress! This document is changing on a daily if not hourly
basis in response to comments and as a general part of its development process.
Comments are very welcome, please send them to htmlforms@damowmow.com and cc
www-archive@w3.org. Thank you.
It is very wrong to cite this as anything other than a work in progress. Do not
implement this in a production product. It is not ready yet! At all!

I'm thinking of contacting them.
"them" is me. :-)

Comment 7

14 years ago
Ian, I was wondering, if as soon as that spec is finalized, if we could just
change the current code for "onchange" so that it works for "oninput" instead. 
The sooner I could get ahold of the "oninput" feature for javascript the better.
 Also, this might give some developers an easier transition once onchange is
corrected in Mozilla.

Comment 8

13 years ago
*** Bug 278065 has been marked as a duplicate of this bug. ***
Assignee: events → nobody
QA Contact: ian → events
Summary: onchange triggered before checkbox loses focus instead of after → onchange triggered before checkbox/radio loses focus instead of after
Duplicate of this bug: 566318
The specs have been changed and now feet our behavior:
"The activation behavior is to fire a simple event that bubbles named change at the element, then broadcast formchange events from the element's form owner, if any."
Last Resolved: 7 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.