how to count the number of characters in a text box

cpp.net Mauritius
  • 14 years ago

    Hi friends,

    Sorry to bother you again, I need to put a text box and have the character count and displayed on another text box as the user is inputing the words in the text box.I'm using VB.Net for coding my project.

    For example                                   text box1 to have the count()

     

    Large text box2 where all input will be made and the characher input has to increment in text box 1.

    Hope that someone can help me.

    Thanks.

     

  • 14 years ago

    Hi Vinay,

    In the larger text box HTML code give onkeydown = "sampleLength()"
    ie: <asp:TextBox runat="server" id="TextBox2" onkeydown = "sampleLength()"></asp:TextBox>


    Then define a javascript function as given below:
    <script language= javascript>
    function sampleLength()
    {
    document.Form1.TextBox1.value = document.Form1.TextBox2.value.length+1;
    }
     </script>

    This will give you the count. You can refine on this for handling back spaces and deletes.
    Now it will give you the count on the other text box when a value is entered.










    Regards
      Udai K




Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Measuring programming progress by lines of code is like measuring aircraft building progress by weight.” - Bill Gates