In my experience, input type=\"text\"
onchange
event usually occurs only after you leave (blur
) the control.
Is there a way to
Update:
See Another answer (2015).
Original 2009 Answer:
So, you want the onchange
event to fire on keydown, blur, and paste? That's magic.
If you want to track changes as they type, use "onkeydown"
. If you need to trap paste operations with the mouse, use "onpaste"
(IE, FF3) and "oninput"
(FF, Opera, Chrome, Safari1).
1Broken for <textarea>
on Safari. Use textInput instead
Below code works fine for me with Jquery 1.8.3
HTML : <input type="text" id="myId" />
Javascript/JQuery:
$("#myId").on('change keydown paste input', function(){
doSomething();
});
onkeyup
happens after you type for example I press t
when I lift the finger the action happens but on keydown
the action happens before I digit the character t
Hope this is helpful for someone.
So onkeyup
is better for when you want to send what you just typed now.
2018 here, this is what I do:
$(inputs).on('change keydown paste input propertychange click keyup blur',handler);
If you can point out flaws in this approach, I would be grateful.
You could use the keydown
, keyup
and keypress
events as well.
If you use ONLY Internet Explorer, you can use this:
<input type="text" id="myID" onpropertychange="TextChange(this)" />
<script type="text/javascript">
function TextChange(tBox) {
if(event.propertyName=='value') {
//your code here
}
}
</script>
Hope that helps.