Problem: I have a javascript function that counts the number of characters in the textarea and outputs it to my console. I also have maxlength
set on my textarea.
The problem is, that sometimes my sum
and textarea maxlength
dont line up.
For example, the textarea would be blocking my input, but the sum varible would show me , that I still have characters left. Especially, when I type fast or when I insert multiple characters at the same time.
How can I solve this? Thanks
HTML:
<textarea maxlength="100"></textarea>
Javascript:
var inputArea = $('textarea');
inputArea.keyup(function(){
var sum = 100 - inputArea.val().length;
console.log(sum);
});
JSFiddle: http://jsfiddle.net/RnTHJ/3/