User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 427,193 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,214 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 705 | Replies: 3 | Solved
Reply
Join Date: Jan 2008
Location: London, England
Posts: 57
Reputation: hooray is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Question simple Javascript counting function

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jan 2008
Location: Bangalore, India
Posts: 336
Reputation: DangerDev is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 32
DangerDev's Avatar
DangerDev DangerDev is offline Offline
Posting Whiz

Re: simple Javascript counting function

  #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......
A computer lets you make more mistakes faster than any invention in human history - with the possible exceptions of handguns and tequila.
~Mitch Ratcliffe
Reply With Quote  
Join Date: Jul 2005
Location: india
Posts: 147
Reputation: katarey is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 16
katarey's Avatar
katarey katarey is offline Offline
Junior Poster

Re: simple Javascript counting function

  #3  
Feb 20th, 2008
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
Last edited by katarey : Feb 20th, 2008 at 1:16 pm.
Freelance Web Designer & Developer
Http//www.Katarey.com
Reply With Quote  
Join Date: Jan 2008
Location: London, England
Posts: 57
Reputation: hooray is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 6
hooray hooray is offline Offline
Junior Poster in Training

Re: simple Javascript counting function

  #4  
Feb 21st, 2008
thanks katarey, that was exactly what I was looking for
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 10:15 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC