PDA

View Full Version : How to make "characters remaining" as we are typing text?


jianneng
08-27-2002, 02:49 PM
Hi,

I have two text boxes, one for typing text, and the other containing the number of characters that is constrained for the typing text. Let say the constraint is 200, so the second text box will initially has the value of 200. As I begin to type something into the first text box, that number, i.e. 200, will begin to reduce in number automatically. For instance, if I had typed "I need help", then the number in the second text box should now display 189.

I know Javascript can do this, but so far I have had problems in trying to access relevant resources for this topic (sorry because I don't really know if my topic is an array topic, a number topic, or something else).

Can someone give me some guidance on this? I would appreciate if you can show me some links to the source code relevant to what I need so that I can study them. Thanks!

PauletteB
08-27-2002, 03:49 PM
Some information can be found on this thread:

Very nice form effect (http://www.codingforums.com/showthread.php?threadid=3753)

Philip M
08-27-2002, 07:26 PM
Here we go!

maxLen = 200; // max number of characters allowed in the textbox
function checkMaxInput(form) {
if (form.Description.value.length > maxLen) // if too long.... trim it!
form.Description.value = form.Description.value.substring(0, maxLen);
// otherwise, update 'characters left' counter
else form.remLen.value = maxLen - form.Description.value.length;
}


The HTML .....

<textarea name=Description font face="ARIAL" cols="60" rows="4" wrap=virtual onKeyDown="checkMaxInput(this.form)" onKeyUp="checkMaxInput(this.form)" ></textarea>

Hope this works for you!