I have an function executed after a keypress event :
$("#txtarea").keypress(function(){
alert(document.getElementById("txtarea").value);
});
I want to return the new text of the textarea after every keypress, so that it can be used simultanuously in other javascript functions.
The problem with this script is that once a key is pressed, the function displays “” empty string.
Thank you in advance.
The keypress just get fired before the value assigned.
Like every other event(click, submit etc’…) so you can cancel the default behavior and “stuff”
You can find out what button was clicked with event.which and work with it.
Example:
JSFiddle DEMO
You can also use the
keyupevent, but it has other meaning and usage thankeypress.Be aware!