Domanda

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.

È stato utile?

Soluzione

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/

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top