What is the best way to grab the last two characters typed into a textarea box?
I need the last 2 characters typed NOT the last two characters of th
You need to catch the keypress
event on the textarea and then keep a log of keys that were pressed. Note that this is going to catch arrow keys, shift, alt, etc so if you just want characters you need to filter them out.
Simple example:
var keyPresses = [];
textarea.onkeypress = function(ev){
ev = ev || window.event;
var key = ev.keyCode || ev.which;
keyPresses.push(key);
}