reneecccwest wrote:
Please discard the previous message. It should be characters instead of words.
can anybody share the code for a character counter for the textarea
user input?
Just use the length property of strings.
document.forms['formname_or_index'].textareaname.value.length
(Tested in IE6, Opera7, Mozilla Firebird, Netscape4.7)
what if max characters are 256?
What do you mean?
You want that the user is not able to type more
characters than 256 into the textarea?
<textarea name="textareaname"
onkeydown="check_chars(256);"></textarea>
And The Function:
function check_chars(iMax)
{
textarea = document.forms['formname_or_index'].textareaname;
if(textarea.value.length >= iMax)
{
// In some Browsers this would work fine:
// return false;
// As it don't work in all, take this:
textarea.value = textarea.value.substr(0, iMax-1);
}
}
This should work fine.
Saludo
Paul.