Saturday, November 5, 2011

How many character remaining code in asp.net

Character count get increment and decrement when it get typed or deleted from textbox


 <script language="javascript">
    function count()
    {
        var keyid=event.KeyCode;

        var c=document.getElementById('TextBox1').value.length;
        if(c<=10)
        {
        document.getElementById('Text1').value=(10-c);
        }
        else
        {
           alert("Character exeed");
        }
  switch (keyid)
 {
    case 8:
    document.getElementById('Text1').value=( document.getElementById('Text1').value - c);
    case 46:
    document.getElementById('Text1').value=(document.getElementById('Text1').value - c);
 }
      
    }
  </script>


 <div>
  
        <asp:TextBox ID="TextBox1" runat="server" onKeyPress="count()" onKeyDown="count()" MaxLength="10"></asp:TextBox>
        <br />
      
    <label>10-></label> <input id="Text1" type="text" disabled="disabled" />
    </div>

No comments:

Post a Comment