How can I get jquery .val() AFTER keypress event?
Posted
by werner5471
on Stack Overflow
See other posts from Stack Overflow
or by werner5471
Published on 2010-06-17T16:06:56Z
Indexed on
2010/06/17
16:13 UTC
Read the original article
Hit count: 195
I got:
$(someTextInputField).keypress(function() {
alert($(this).val());
});
Now the alert always returns the value BEFORE the keypress (e.g. the field is empty, I type 'a' and the alert gives me ''. Then I type 'b' and the alert gives me 'a'...). But I want the value AFTER the keypress - how can I do that?
Background: I'd like to enable a button as soon as the text field contains at least one character. So I run this test on every keypress event, but using the returned val() the result is always one step behind. Using the change() event is not an option for me because then the button is disabled until you leave the text box. If there's a better way to do that, I'm glad to hear it!
© Stack Overflow or respective owner