funeralcrasher: (Default)
funeralcrasher ([personal profile] funeralcrasher) wrote2008-04-09 11:06 am

Trigger action when form input text changes

So is there a way for Javascript to detect when a textbox changes, before onBlur?

I thought onChange would work, but it seems to act just like onBlur: http://www.sunybroome.edu/~hinton_r/js/blurchangeframe.html (comparison of onBlur and onChange in same page)


[identity profile] bedivere.livejournal.com 2008-04-09 03:59 pm (UTC)(link)
Thats actually a bit more of a pain in the butt than one would think. There's no DOM event that really signifies when a input value changes as you jump from field to field (I'm assuming thats what you're trying to trap). You can attach an event handler to the text field and trap the "onFocus" event, capture the current value.. then trap the "onBlur" event as the user leaves the field, and you can compare the current and previous value and see if they've changed. Yahoo UI (http://developer.yahoo.com/yui/) has some libraries that make doing that a bit easier.
(deleted comment) (Show 1 comment)