Вопрос

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.

Это было полезно?

Решение

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/

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top