Forum Moderators: open

Message Too Old, No Replies

counting characters on a line in a textarea

         

proper_bo

12:13 pm on May 5, 2006 (gmt 0)

10+ Year Member



I am a novice when it comes to javascript so all the help you can give me would be great.
I would like to count the characters on each line of a textarea. I am not so bothered about limiting it (although that is probably a good idea) and want to alert when the user reaches the limit.

So the plan is to get the content of the text box. Split it into an array of lines with \n or \r, find the current cursor location and get that line. count the line and spit the result to a textbox.

Sound possible?
I have never used cursor position before.

proper_bo

12:02 am on May 12, 2006 (gmt 0)

10+ Year Member



I am still looking for advice on this.

Anyone?

proper_bo

1:26 pm on May 18, 2006 (gmt 0)

10+ Year Member



I have found loads of stuff for whole textarea. Is there no way of doing this on just one line of the textarea?

jshanman

1:40 pm on May 18, 2006 (gmt 0)

10+ Year Member



A quick google search for "textarea cursor position" returns a script that appears to at least find the cursor position...

Is it that you want the character count of each seperate line to be limited?

It would be simple enough to detect that (using your method of splitting/counting), then alert the user that line x has too many characters. I would assume that if you run the check in an onchange, then whatever line they are currently editing would be the problem line, so you could just say "you've entered too many characters on this line", and the user would assume it is referring to the line on which they are currently typeing...

- JS

proper_bo

2:06 pm on May 18, 2006 (gmt 0)

10+ Year Member



Thanks JS,

I will have a look at this when I have more time.