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.

[identity profile] pkbarbiedoll.livejournal.com 2008-04-10 04:20 am (UTC)(link)
I ended up with onKeyPress to check to see if the textarea is blank. It works perfectly for my needs.

[identity profile] bedivere.livejournal.com 2008-04-10 02:55 pm (UTC)(link)
Ah.. right on then. I used that once for a client that wanted all input values to db saved to the database in all uppercase (for reasons too inane to go into), so I hadda trap that and convert character typed to uppercase.

Re: crazy question...

[identity profile] pkbarbiedoll.livejournal.com 2008-04-10 05:14 pm (UTC)(link)
If you can send the xls to adrya.stembridge@gmail.com I'll return it with properly formatted email addresses in a To: field.