Hello,
I have a text area box that I want to limit to 500 characters. I have a little Javascript function that is triggered by the textarea's onkeypress event. The event adds one to a global variable and when the variable reaches 501, an alert box pops up.
That all works well, but I need to account for the user pressing the backspace key. Right now, my code looks like this, but the backspace if statement seems not to be working:
function countcomchar()
{
//check for backspace, decrease counting var by 2
if (window.event.keyCode==8){
charcount = charcount-2}
else{
//if not backspace, add one to counting var
charcount = charcount+1;
}
//when counting var reaches 501, give a warning
if (charcount > 501){
var mesg
mesg = "You exceeded 500 characters."
alert(mesg);
}
}
Any help would be much appreciated.
Thanks,
Ann