Home

Live Character Count Using JavaScript

Published on 6th Mar 2018 in JavaScript

In this tutorial, we are going to see how to count character live using JavaScript. In previous tutorial we have discussed about how to live preview using jquery. Getting string length using .length property. Length property return length of a string. The innerHTML property is used to set the HTML content of an element.

Live Character Count Using JavaScript

 Live Demo  Download

JavaScript code

     <script>
       function characterCount(txt)
       {
          var strLength = txt.length;
          
          document.getElementById("result").innerHTML = strLength;
       }
        </script>

HTML code

         <textarea onkeyup="characterCount(this.value);" cols="10" rows="15"></textarea>
                 
            <b> Total character:</b> <span id="result"></span>

Share It
Stay Connected
Like Us on Facebook