simple Javascript counting function

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved

Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

simple Javascript counting function

 
0
  #1
Feb 20th, 2008
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:

  1. <td><input type="text" name="description" maxlength="30" /></td>
  2. <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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 483
Reputation: DangerDev has a spectacular aura about DangerDev has a spectacular aura about 
Solved Threads: 58
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Pro in Training

Re: simple Javascript counting function

 
0
  #2
Feb 20th, 2008
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......
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 154
Reputation: katarey is an unknown quantity at this point 
Solved Threads: 20
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: simple Javascript counting function

 
1
  #3
Feb 20th, 2008
Hi There,

Try This Code

JavaScript:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript">
  2. function valueChange(){
  3. textBox1 = document.getElementById('textBox1');
  4. description = document.getElementById('description');
  5. textBox1.value = description.value.length;
  6. }
  7. </script>

HTML:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <input type="text" name="description" maxlength="30" id="description" onkeyup="valueChange()" /></td>
  2. <input type="text" class="counter" readonly="readonly" id="textBox1" />

Rahul Dev Katarey
Last edited by katarey; Feb 20th, 2008 at 2:16 pm.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 62
Reputation: hooray is an unknown quantity at this point 
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: simple Javascript counting function

 
0
  #4
Feb 21st, 2008
thanks katarey, that was exactly what I was looking for
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC