Forum Moderators: open
I do something like:
if(document.myForm.myTextarea.value.length > 300)
{
alert("Max: 300 characters");
}
But Firefox sees newlines as 1 character while IE sees them as 2 characters!
Example, my textarea:
---------------
0123456789
0123456789
---------------
Firefox thinks there are 21 characters.
IE thinks there are 22 characters.
How can I count correctly for any browser?
But anyway, I think this will do the job:
document.myForm.myTextarea.value.replace(/\r\n/g,'x').length > 300
"\r" (ex: on mac) counts for one char, "\n" (ex: on Firefox) counts for one char and with this little script, "\r\n" (ex: on IE) also counts for one char.
Thanks again for your help!