0

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.

3
Contributors
3
Replies
6
Views
9 Years
Discussion Span
Last Post by hooray
Featured Replies
  • Hi There, Try This Code JavaScript: [CODE] <script type="text/javascript"> function valueChange(){ textBox1 = document.getElementById('textBox1'); description = document.getElementById('description'); textBox1.value = description.value.length; } </script> [/CODE] HTML: [CODE]<input type="text" name="description" maxlength="30" id="description" onkeyup="valueChange()" /></td> <input type="text" class="counter" readonly="readonly" id="textBox1" />[/CODE] Rahul Dev Katarey Read More

0

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

1

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

Votes + Comments
Brilliant, thanks
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.