Thursday, March 29, 2007

The 'onchange' event

My recent dojo work has led me to exploring JavaScript event reassignment and specifically to the intricacies of the onchange event of html input elements.

The HTML 4.01 Specification says this about the onchange event:
"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."

Okay. Well currently Firefox doesn't follow this (at least for radio buttons), but instead does something outrageous; it fires an onchange event if something changes, for example, if the radio button checked state changes. (Although I hear it "correctly" fires onchange for a text input only when it loses focus; perhaps to avoid the event noise that would occur during text entry).

Sarcasm aside, I imagine there are good reasons for the HTML Specification but I can't help but think, at least in the post submit-page-refresh model of web development, that we could stand to have a more immediate onchange event, perhaps called onvaluechange?

Some hacky vanilla test code is in my exploratory. Yes, I've taken a liking to using the word exploratory as a noun.

7 comments:

David Bolter said...

Oops. I wrote "post submit-page-refresh model of web development" but I should have written something like "new age of rich interactive web application development".

Wladimir Palant said...

IE fires change events on SELECT whenever selection changes - which is pretty ugly if you look at accessibility. This function is most often used to send you off to some different part of the page if you make a choice. But if you select with the keyboard the selection will change several times, so it is pretty impossible to use. I prefer the way it is implemented in Firefox though I have seen some quite heated debates on this between web developers.

Simon Geard said...

Found similar issues with the behaviour of drop-down boxes the other day. Selecting a value from the box with the keyboard, onchange handling is fired immediately a value is selected. Selecting with the keyboard, it fires only when focus leaves the box.

This caused some confusion over handlers updating other fields on the screen...

Android app development said...

This is one of the knowledgeable post.This is one of the valuable information.Thanks for your support.
Android app developers

Fastbet said...

What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say. Im sure youll reach so many people with what youve got to say. Agen Sbobet Ibcbet.com Online Sbobet.com Online

Fastbet said...

You got numerous positive points there. I made a search on the issue and found nearly all peoples will agree with your blog. Judi Bola Agen Ibcbet

Richard Majece said...

What about important info, I recommend you to read https://besttrackingapps.com/android-hacking-apps/ . You can learn a lot about hacking apps using these advices.