JavaScript Code

Count the Number of Characters with JavaScript

Sometimes you need a quick way to count the number of characters in a string. Suppose you're limiting a textarea to 1000 characters, you'll want to show the user how much more they can type. Or, perhaps a forum limits your signature length, and you want a quick way to validate it (including BB Code markup). This handy little code snippet provides a textarea and the inline JavaScript to display the number of characters.

<form name="form_count">
<textarea rows="8" name="char_input" cols="40" wrap="virtual" onkeyup="f=document.form_count;f.char_count.value=f.char_input.value.length;"></textarea>
<p><input type="button" value="Calculate Characters" onClick="f=document.form_count;f.char_count.value=f.char_input.value.length;"> 
<input type="text" name="char_count" size="20"></p>

Here's what it looks like:



  1. Thanks for the Javascript… i was searching for this type of Dynamically displaying script from a very long time…

    Thanks once again 🙂

  2. Many thanks for the script…very compact. It will be useful my site

  3. Oh Very nice script, actually I got confused first, then I found this is a very good and small script. Thanks, Good Work. 🙂

  4. I want to test this code. So I want to see the process.

Leave a Reply

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

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image