I want to count characters in a textarea, so I just made:
<textarea id="field" onkeyup="countChar(this)"></textarea>
function countChar(val){
var len = val.value.length;
if (len >= 500) {
val.value = val.value.substring(0, 500);
} else {
$('#charNum').text(500 - len);
}
};
What's wrong with my piece of code? It does not work! Well, that was a newbie handwriting, need a help.
HTML sample, used wherever I need a counter, notice the relevance of IDs of textarea and second span :
id="post"
<->id="rem_post"
and the title of the span that holds the desired characters amount of each particular textareaJavaScript function, usually placed before
</body>
in my template file, requires jQueryWell, this is not that different from what have been said, but this works very well in all browsers.
The idea is to delete any text which overflows the defined length.
The HTMl code would be: