Friday, 5 July 2013

text box Character Counter

Textbox   character Counter 

  • In the <HEAD> tag of the design page(.aspx) create the JavaScript functions as: 
<script type="text/javascript">

        function characterCounter(controlId, countControlId, maxCharlimit) {

            if (controlId.value.length > maxCharlimit)
                controlId.value = controlId.value.substring(0, maxCharlimit);
                countControlId.value = maxCharlimit - controlId.value.length;


  • In the <BODY> tag copy and paste the following:

<fieldset style="width:280px;">
            <legend>Counting Remaining Characters example</legend>
             <asp:TextBox ID="txtComments" Width="280px" Rows="4" Columns="12"runat="server" TextMode="MultiLine"  onkeyup="characterCounter(txtComments, this.form.remCount, 150);" onkeydown="characterCounter(txtComments, this.form.remCount, 150);" />
<input  type="text" name="remCount" size="3" maxlength="3" value="150"readonly="readonly" /> characters left

No comments:

Post a Comment