Reputation: 19
I have this problem with counting element's value length in textarea.
I tried both DOM and jQuery, but it seems like .length
is the problem. I alerted $('#' + field1).val().length
and it seems that it starts counting from 0 even though there is 1 symbol in a field.
BTW $('#' + field1).val().length + 1
doesn't help, it even makes it worse.
Here the JSFiddle with my code.
Upvotes: 0
Views: 94
Reputation: 6004
Change the event from onkeypress
to onkeyup
. The problem is that the javascript is counting the characters before the character has actually been entered into the textarea.
Working fiddle: http://jsfiddle.net/YbUf4/8/
Upvotes: 2