Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Member
10 Points
5 Posts
May 13, 2009 04:55 PM|LINK
Sure thing, here's the script in the <head>:
<script type="text/javascript" language="Javascript"> //Character count script! function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit); else countfield.value = maxlimit - field.value.length; } </script>
And here is the <asp:TextBox> where the script is invoked:
<asp:TextBox ID="uxCommentsNoTextbox" runat="server" Height="100" Width="550" Wrap="true" TextMode="MultiLine" onkeyup="textCounter(uxCommentsNoTextbox, this.form.uxCommentsCharCount, 1500);" onkeydown="textCounter(uxCommentsNoTextbox, this.form.uxCommentsNoCharCount, 1500);" />
And the above is referring to an input field with id of "uxCommentsCharCount", which is here:
<input readonly="readonly" type="text" id="uxCommentsNoCharCount" name="uxCommentsNoCharCount" size="4" maxlength="4" value="" style="border: solid 0px white; background: white;" />
thohan
Member
10 Points
5 Posts
Re: Character Counter for Multiline Textbox
May 13, 2009 04:55 PM|LINK
Sure thing, here's the script in the <head>:
<script type="text/javascript" language="Javascript"> //Character count script! function textCounter(field, countfield, maxlimit) { if (field.value.length > maxlimit) field.value = field.value.substring(0, maxlimit); else countfield.value = maxlimit - field.value.length; } </script>And here is the <asp:TextBox> where the script is invoked:
<asp:TextBox ID="uxCommentsNoTextbox" runat="server" Height="100" Width="550" Wrap="true" TextMode="MultiLine" onkeyup="textCounter(uxCommentsNoTextbox, this.form.uxCommentsCharCount, 1500);" onkeydown="textCounter(uxCommentsNoTextbox, this.form.uxCommentsNoCharCount, 1500);" />And the above is referring to an input field with id of "uxCommentsCharCount", which is here:
<input readonly="readonly" type="text" id="uxCommentsNoCharCount" name="uxCommentsNoCharCount" size="4" maxlength="4" value="" style="border: solid 0px white; background: white;" />So I'm using an input instead of a <span>, and the inline style I have makes it look like just text and not an input box.