how can I cater for any backspaces? (I a user deletes a character the number of characters left increases by 1)?
Just work on the math bit as it is not accurate
I've used this one before and it was dead easy to use. It was quite a clean and tidy addition to one of my major forms.
use keyup instead of keypress. just tried it and it worked better.
var textLen = $(this).val().length;
var textLeft = parseInt($(this).attr("maxlength")) - textLen;
textLeft + ' character' + (textLeft == 1 ? '' : 's') + ' left'
I dont think that line 9 in your sample is needed.. or line 14 from the last jsfiddle example..yes/no?
line 9 - $('#txtbox').keyup();
jsfiddle, line 14 $('#txtbox').keypress();
that line is just starting the string when the page loads.
very helpful all, all I had to do was keyup instead of keypress and worked like a charm. THanks
keydown would be more accurate as it will fire when someone keeps the button pressed in as well.