September 11th, 2006

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>
</form>

Here's what it looks like:

One Response to ' Count the Number of Characters with JavaScript '

Subscribe to comments with RSS or TrackBack to ' Count the Number of Characters with JavaScript '.

  1. kavitha said,

    on April 14th, 2008 at 5:44 am

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

    Thanks once again :)

Leave a reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
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.
Click to hear an audio file of the anti-spam word