943,879 Members | Top Members by Rank

Ad:
Feb 20th, 2008
0

simple Javascript counting function

Expand Post »
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:

html Syntax (Toggle Plain Text)
  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.
Similar Threads
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008
Feb 20th, 2008
0

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......
Reputation Points: 165
Solved Threads: 59
Posting Pro in Training
DangerDev is offline Offline
485 posts
since Jan 2008
Feb 20th, 2008
1

Re: simple Javascript counting function

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.
Reputation Points: 39
Solved Threads: 23
Junior Poster
katarey is offline Offline
167 posts
since Jul 2005
Feb 21st, 2008
0

Re: simple Javascript counting function

thanks katarey, that was exactly what I was looking for
Reputation Points: 11
Solved Threads: 6
Junior Poster in Training
hooray is offline Offline
62 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: I need HTML Dropdown Buttons to freeze Flash animation below it! urgent!please help!
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: drop down menu going behind flash element please help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC