Join TalkersCode Now !

Get Latest Tutorials And Links On Web Development
And Get Existing Offers Via Email

Live Character Count Using JavaScript

Saturday, Apr 8, 2017

Tags:- JavaScript


In this tutorial we will show you how to count characters live using JavaScript.You may also like Live Voting System Using Ajax And PHP


See Demo
Live Character Count


To count characters live it takes only one step:-

  1. Make a HTML file and define markup,script


Step 1.Make a HTML file and define markup,script

We make a HTML file and save it with a name count.html

<html>
<head>
<script type="text/javascript">
function count()
{
  var total=document.getElementById("text").value;
  total=total.replace(/\s/g, '');
  document.getElementById("total").innerHTML="Total Characters:"+total.length;
}
</script>
</head>
<body>
<div id="wrapper">
 <textarea id="text" onkeyup="count();" placeholder="Enter Some Text"></textarea>
 <p id="total">Total Characters:0</p>
</div>
</body>
</html>

In this step we make a textbox and use onkeyup event to call count() function on every key press and under count() function we get the text written on textbox and then we remove the white space beacuse we have to count only characters and after that we display the total count.You may also like Add And Remove Textbox Using JavaScript


Thats all, this is how to Count Characters Live Using JavaScript.You can customize this code further as per your requirement. And please feel free to give comments on this tutorial.

Join Us With Our 21000+ Subscribers And Get Our Latest Tutorials Update Via Email

Are You Starting A New Blog
Do You Want Best Web Hosting?

Try World's Best Web Hosting Provider BlueHost
At Just $3.95/mo

Hurry Up! Limited Time Offer

Yes, I Want To Check Out BlueHost

Check The World's Best SEO And All-In-One Marketing Toolkit
For Digital Marketing Professionals SEMRUSH

Check Out SEMRUSH