I have an <input> textbox.
I wish to call a function when it has been modified. The default behavior of the change event is to only trigger on blur, but I need to call my function as soon as the textbox’s text changes and can’t wait for blur.
I’m not sure the best way to do this. I thought of maybe handling keydown and then testing the value of the keyCode for a key that would modify the value. So… ignore arrow keys, etc. But that seems awkward and I don’t think I can figure out the test to make it work.
I also thought about recording the inital value and comparing to this value but then I wouldn’t be notified in the case when the value changes back to the original.
Maybe there’s a better way?
I’d appreciate any suggestions.
a combination of
focusandkeyupis probably your best bet. record the initial value in thefocushandler, and check against the current value in thekeyuphandler. (the new input value, if any, is available whenkeyupfires).