Javascript for character count on keypress
<script language="javascript"
type="text/javascript">
maxL = 1000;
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>
==================================================
It is used like as mention below
<asp:TextBox ID="txtImportaintInfo" runat="server"
TextMode="MultiLine"
CssClass="textarea_field2" onpaste="return false" onkeypress="return taLimit(this)"
onkeyup="return taCount(this,'myCounter1')"></asp:TextBox>
<br /> You have <b><span
id="myCounter1">1000</span></b>
characters remaining for your
description...</td>
maxL = 1000;
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>
It is used like as mention below
<asp:TextBox ID="txtImportaintInfo" runat="server" TextMode="MultiLine"
CssClass="textarea_field2" onpaste="return false" onkeypress="return taLimit(this)" onkeyup="return taCount(this,'myCounter1')"></asp:TextBox>
<br /> You have <b><span id="myCounter1">1000</span></b>
characters remaining for your description...</td>
No comments:
Post a Comment