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.

Recommended Answers

All 3 Replies

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

JavaScript:

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

HTML:

<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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.