user393273
user393273

Reputation: 1438

onChange is called only when the element loses focus

I want that as you type in the textfield the div changes (I have the code for changing the div already). However the onchange event is only called once you are finished and click outside the textfield. I want it to be called as each letter is typed.

My code:

<input name="platetext" type="text" onchange="setValue(this)">

Upvotes: 0

Views: 7711

Answers (2)

Murphy
Murphy

Reputation: 131

There is an 'input' Event you can bind your event Handlers to (I think this was introduced with HTML5).

I made a quick and very dirty example here: http://jsfiddle.net/RdKZH/

This would be the clean approach to this problem (as keyup does not work on copy&paste), but you might want to test if it already works in all browsers you want to support.

Upvotes: 5

Jan Zyka
Jan Zyka

Reputation: 17888

onChange is fired when the input looses focus I think. onKeyUp should do the trick for you.

Upvotes: 9

Related Questions