473,327 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

character counter

Please discard the previous message. It should be characters instead of words.
can anybody share the code for a character counter for the textarea
user input? what if max characters are 256?

thanks
Jul 20 '05 #1
1 4404
reneecccwest wrote:
Please discard the previous message. It should be characters instead of words.
can anybody share the code for a character counter for the textarea
user input?
Just use the length property of strings.

document.forms['formname_or_index'].textareaname.value.length

(Tested in IE6, Opera7, Mozilla Firebird, Netscape4.7)
what if max characters are 256?


What do you mean?
You want that the user is not able to type more
characters than 256 into the textarea?

<textarea name="textareaname"
onkeydown="check_chars(256);"></textarea>

And The Function:

function check_chars(iMax)
{
textarea = document.forms['formname_or_index'].textareaname;
if(textarea.value.length >= iMax)
{
// In some Browsers this would work fine:
// return false;
// As it don't work in all, take this:
textarea.value = textarea.value.substr(0, iMax-1);
}
}

This should work fine.

Saludo
Paul.
Jul 20 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matthew | last post by:
Hello ~ I am looking for a character counter that will display the remaining number of characters left in a form box, that will also display adjust for default values on the form
1
by: Mats Bue | last post by:
Hi I am working on an application where I need to parse C# source code. For example, I need to find the return statement in a method. So I search for the word "return" in a line of code. But the...
18
by: SwordAngel | last post by:
Hello, I'm looking for a program that converts characters of different encodings (such as EUC-JP, Big5, GB-18030, etc.) into HTML ampersand escape sequences. Anybody knows where I can find one? ...
37
by: chandy | last post by:
Hi, I have an Html document that declares that it uses the utf-8 character set. As this document is editable via a web interface I need to make sure than high-ascii characters that may be...
5
by: Magix | last post by:
Hi, my text file contains many lines of text, some of the text contains EOF character appended at the end of the text. if I use: while (fgets(buffstr, sizeof(buffstr), in_ptr)!=NULL), it will...
3
by: linguae | last post by:
Hello. In my C program, I have an array of character pointers. I'm trying to input character strings to each index of the character pointer array using scanf(), but when I run the program, I get...
16
by: thenightfly | last post by:
Ok, I know all about how binary numbers translate into text characters. My question is what exactly IS a text character? Is it a bitmap?
2
by: Thejan Mendis | last post by:
Hi all, I need to check whether my richtextbox contain any blank line. the source I try to used in below. but it not reflect the output I need. basically I need the collect the paragraph by...
7
by: libsfan01 | last post by:
hi all how do u get js to work out the number of times a given char occurs in a given string? regards Marc
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.