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>
<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:

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