$("#some-form-text-input").live("keypress", function(e){
alert($("#some-form-text-input").val());
});An example of why this is undesirable is: if the text field already contained the string "somethin" and "g" is typed next, the alert in the callback would only display "somethin" versus the desired "something".
Solution: use the "keyup" rather than the "keypress" event
E.g.
$("#some-form-text-input").live("keyup", function(e){
alert($("#some-form-text-input").val());
}); This waits until the latest pressed key is lifted before firing the callback.
No comments:
Post a Comment