tags:

views:

67

answers:

2

As far as I understand, the "onchange" event of a text input element is only fired when two conditions are true:

  • The text has changed.
  • The field no longer has focus.

So when you click off, it fires the event. How can I fire an event when the text has changed, but the field still has focus?

+1  A: 

you have access to the keypress, keyup, and keydown events; the details of when those fire can be found at Quirksmode.

DDaviesBrackett
thanks for the Quirksmode link!
Andrew
+2  A: 

Reliably? You can't, yet.

You can catch the majority of changes by firing your update checker onkeyup as well as onchange. However whilst this picks up simple keyboard interactions, it fails to trigger on other events like cut-and-paste (there is onpaste in some browsers, but you can't rely on it), drag-and-drop, undo-redo and spellchecker changes.

HTML5 proposes oninput to solve this, but the implementation isn't there yet. If you really want to spot all input changes today you will have to setInterval a function that keeps checking the input's value to see if it has changed.

bobince
+1 - for pointing out the trigger for paste
Ramesh