Live Character Count Using JavaScript

Live Character Count Using 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 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>

Leave a Reply

Your email address will not be published. Required fields are marked *