Gezna
asked on
Character Counter for Multiline Textbox
Does anyone know how to modify the javascript below in order for this character counter to work with a multiline textbox rather than a textarea?
This is the control I want to use:
***************
<asp:TextBox id="Description2" runat="server" Height="136px" Width="352px" TextMode="MultiLine"
MaxLength="255"></asp:Text Box>
***************
This is the script and html that is working:
***************
<script language="Javascript">
function taLimit() {
var taObj=event.srcElement;
if (taObj.value.length==taObj .maxLength *1) return false;
}
function taCount(visCnt) {
var taObj=event.srcElement;
if (taObj.value.length>taObj. maxLength* 1) taObj.value=taObj.value.su bstring(0, taObj.maxL ength*1);
if (visCnt) visCnt.innerText=taObj.max Length-taO bj.value.l ength;
}
</script>
<form id="Form1" method="post" runat="server">
<table>
<tr>
<td>
<font>Maximum Number of characters for this text box is 255.<br>
<TEXTAREA runat="server" onkeypress="return taLimit()" onkeyup="return taCount (myCounter)" name="Description" rows="7" wrap="physical" cols="40" maxLength="255"></TEXTAREA >
<br>
You have <B><SPAN id="myCounter">255</SPAN>< /B> characters remaining for your description...</font>
</td>
</tr>
</table>
</form>
***************
This is the control I want to use:
***************
<asp:TextBox id="Description2" runat="server" Height="136px" Width="352px" TextMode="MultiLine"
MaxLength="255"></asp:Text
***************
This is the script and html that is working:
***************
<script language="Javascript">
function taLimit() {
var taObj=event.srcElement;
if (taObj.value.length==taObj
}
function taCount(visCnt) {
var taObj=event.srcElement;
if (taObj.value.length>taObj.
if (visCnt) visCnt.innerText=taObj.max
}
</script>
<form id="Form1" method="post" runat="server">
<table>
<tr>
<td>
<font>Maximum Number of characters for this text box is 255.<br>
<TEXTAREA runat="server" onkeypress="return taLimit()" onkeyup="return taCount (myCounter)" name="Description" rows="7" wrap="physical" cols="40" maxLength="255"></TEXTAREA
<br>
You have <B><SPAN id="myCounter">255</SPAN><
</td>
</tr>
</table>
</form>
***************
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
just an addition, the multiline asp:textbox control is rendered as textarea in html
Regards,
B..M