Count characters in a textarea.

You just need the bolded text…


<script type=”text/javascript”>
function textCounter(textarea, counterID, maxLen) {
cnt = document.getElementById(counterID);
if (textarea.value.length > maxLen)
textarea.value = textarea.value.substring(0,maxLen);
cnt.innerHTML = maxLen – textarea.value.length;

<form action=”whatever.php”>

<textarea name=”text_area” cols=”50″ rows=”5″ onKeyUp=”textCounter(this,’count_display’,3500);” >
onBlur=”textCounter(this,’count_display’,3500);” >

<span id=”count_display”>3500</SPAN> characters remaining

<input type=”submit” value=”Submit”>


One Response to “Count characters in a textarea.”

  1. hyder Says:

    Nice code . I have implemented a similar stuff using Jquery . You can find the tutorial here :

    The difference with this one is that i have implemented a progress bar based on the number of characters entered .
    Enjoy !

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: