In my experience, input type="text"
onchange
event usually occurs only after you leave (blur
) the control.
Is there a way to force browser to trigger onchange
every time textfield
content changes? If not, what is the most elegant way to track this “manually”?
Using onkey*
events is not reliable, since you can right-click the field and choose Paste, and this will change the field without any keyboard input.
Is setTimeout
the only way?.. Ugly 🙂
Best Answer
These days listen for
oninput
. It feels likeonchange
without the need to lose focus on the element. It is HTML5.It’s supported by everyone (even mobile), except IE8 and below. For IE add
onpropertychange
. I use it like this: