First off, let me say I know nothing about javascript. I have been searching the web the last couple days to find a character counter to add to a textarea. I finally found a nifty little script (working example) that works great except for one problem. When you reach the maximum number of characters allowed in Firefox, the entire keyboard is disabled. You can't backspace to shorten the count or click in the middle and delete. Works fine in IE, Chrome and Safari but not in FireFox. My request is, can someone help me alter the javascript so the backspace and delete buttons are enabled in FireFox when the maximum number of characters is reached.
Thanks for all the help.
JavaScript Code
<script language = "Javascript">
maxL=255;
var bName = navigator.appName;
function taLimit(taObj) {
if (taObj.value.length==maxL) return false;
return true;
}
function taCount(taObj,Cnt) {
objCnt=createObject(Cnt);
objVal=taObj.value;
if (objVal.length>maxL) objVal=objVal.substring(0,maxL);
if (objCnt) {
if(bName == "Netscape"){
objCnt.textContent=maxL-objVal.length;}
else{objCnt.innerText=maxL-objVal.length;}
}
return true;
}
function createObject(objId) {
if (document.getElementById) return document.getElementById(objId);
else if (document.layers) return eval("document." + objId);
else if (document.all) return eval("document.all." + objId);
else return eval("document." + objId);
}
</script>
HTML Code
<font> Maximum Number of characters for this text box is 255.<br>
<textarea onKeyPress="return taLimit(this)" onKeyUp="return taCount(this,'myCounter')" name="Description" rows=7 wrap="physical" cols=40>
</textarea>
<br><br>
You have <B><SPAN id=myCounter>255</SPAN></B> characters remaining for your description...</font>