Ayush
Ayush

Reputation: 42450

Onchange event that does not wait for input box to lose focus

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

Answers (3)

Tim Down
Tim Down

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

Jon
Jon

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

Richard Dalton
Richard Dalton

Reputation: 35803

You can use onkeyup instead

<input type="text" id="fname" onkeyup="upperCase(this.id)">

http://jsfiddle.net/McjqW/1/

Upvotes: 2

Related Questions