Tuesday, March 29, 2011

Count Charactes in a TextBox by using JavaScript.

<asp:TextBox ID="txt_message" runat="server" CssClass="textarea" Height="100px" onkeyup="validatelimit(this)" TextMode="MultiLine" Width="250px"></asp:TextBox>

//Key Press Event
 function validatelimit(obj)
 {
    if(this.id)
    obj=this;   
    var i=obj.value.length;
    document.getElementById('<%= lbl_ccount.ClientID %>').innerHTML=i;
    if(1>0)
    {
        var q=i/160;
        var r=i%160;       
         if(r==0)
         {
            q=Math.round(q);
            document.getElementById('<%= lbl_mcount.ClientID%>').innerHTML=q;
         }
         else
         {
           q=Math.floor(q);                   
           document.getElementById('<%=lbl_mcount.ClientID%>').innerHTML=q+1;
          }   
       }
    else
    {
        document.getElementById('<%= lbl_mcount.ClientID %>').innerHTML=0;
    }
 }

No comments:

Post a Comment