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 

[sociallocker] Download[/sociallocker]

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 Comment