Reputation: 42450
The onchange
event for a HTML input box does not fire until the textbox loses focus. Is there a way to make it fire as soon as the contents change?
Here's an example of onchange
firing after focus loss: http://jsfiddle.net/McjqW/
Upvotes: 0
Views: 4773
Reputation: 324717
You need the HTML5 input
event. It's not quite fully cross-browser but there's a workaround for IE < 9, which is the only major browser that doesn't have it. See here and here.
Upvotes: 1
Reputation: 437854
You are looking for the onkeypress
or onkeydown
event. Note that this event is not standard, and different browsers may expose this functionality under different names. The DOM level 3 standard defines a keypress
event which would be "the" answer, but again I can't vouch for browser support.
Update: onkeypress
reportedly enjoys wide support.
Upvotes: 1
Reputation: 35803
You can use onkeyup instead
<input type="text" id="fname" onkeyup="upperCase(this.id)">
Upvotes: 2