DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   simple Javascript counting function (http://www.daniweb.com/forums/thread109998.html)

hooray Feb 20th, 2008 8:42 am
simple Javascript counting function
 
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.

DangerDev Feb 20th, 2008 8:54 am
Re: simple Javascript counting function
 
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......

katarey Feb 20th, 2008 1:14 pm
Re: simple Javascript counting function
 
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

hooray Feb 21st, 2008 9:08 am
Re: simple Javascript counting function
 
thanks katarey, that was exactly what I was looking for


All times are GMT -4. The time now is 3:39 pm.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC