views:

903

answers:

1

Hello, myInput.value is one keystroke behind when I examine it in a keyPress event handler. So if the users types "a", myInput.value gives me "". Then when the user types "b", myInput.value gives me "a", and so it. The value doesn't seem to get updated with the character input by the keystroke that triggered the event. What am I doing wrong? thanks -Morgan

+5  A: 

Use the keyUp event, it should definitely give you the value you are looking for.

sandesh247
Yep. The new keypress is applied to the value *after* calling onkeypress — as long as you don't cancel that event by returning false from your handler. Keyup, on the other hand, happens after the keypress has finished.
bobince
great. works perfect. thanks.
morgancodes