Thursday, April 28, 2016

jQuery- Count characters in textarea

Topic: 1.Character Counting Remaining on textarea using jQuery.
Topic: 2. jQuery- Count characters in textarea
Topic: 3. How can I count characters in textarea on onkeyup() event using jQuery?
 
We can find above topics solutions in below code.

 
<!DOCTYPE html>
<html>
  <head>
    <script src="http://code.jquery.com/jquery-1.5.js"></script>
    <script>
      function countChar(val) {
        var len = val.value.length;
        if (len >= 500) {
          val.value = val.value.substring(0, 500);
        } else {
          $('#charNum').text(500 - len);
        }
      };
    </script>
  </head>

  <body>
    <textarea id="field" onkeyup="countChar(this)"></textarea>
    <div id="charNum"></div>
  </body>

</html>

No comments :

Post a Comment