Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Limit the Character Count in Textarea in Jquery

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 301
    Comment on it

    Hello Readers,

    Here, I will tell you about the character limit on textarea using Jquery.

    For Example, If the character limit to write on textarea is 100 character ,then we write only 100 character on the textarea not more than 100.

    Therefore, we use a simple input box like Textarea and to check the character count using simple Jquery. In input box user just enter any input and all the other work is done by Jquery.

    In this function, We set the number of characters to be inserted. Here we have a input box and we place any number of input value and check the length of that input value with the characters we input into the textarea ,if the input value is greater than the character than we will use the substring function after that every input value counter will be decremented,when user input one character into the input box and this process continue until the counter will be decremented up to zero.

    The code is given below:

    <html>
      <head>
        <script src="http://code.jquery.com/jquery-1.5.js"></script>
        <script>
          function countChar(val) {
            var len = val.value.length;
            if (len >= 100) {
              val.value = val.value.substring(0, 100);
            } else {
              $('#charNum').text(100 - len);
            }
          };
        </script>
      </head>
    
      <body>
        <textarea id="field" onkeyup="countChar(this)"></textarea>
        <div id="charNum"></div>
      </body>
    </html>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: