Hi, i have a form on my website, and I would like to have a text box next to another text box that displays how many letters the user can type into the box eg:

<td><input type="text" name="description" maxlength="30" /></td>
<td><input type="text" class="counter" value="30" disabled="true" /></td>

This is fine, but I would like the box with the numbers in it to count down as the user types in the first box, and if they delete something i would like the number to go back up again too.

If anyone could help me that'd be great thanks.

use onkeydown event in text box,
in this event write a function which will take value of textbox check the length of string and then print the no. in the box......

Hi There,

Try This Code


<script type="text/javascript">
function valueChange(){
		textBox1 = document.getElementById('textBox1');
		description = document.getElementById('description');
		textBox1.value = description.value.length;


<input type="text" name="description" maxlength="30" id="description" onkeyup="valueChange()" /></td>
<input type="text" class="counter" readonly="readonly" id="textBox1" />

Rahul Dev Katarey

commented: Brilliant, thanks +1

thanks katarey, that was exactly what I was looking for