Gossamer Forum
Home : General : Internet Technologies :

Javascript Q. - Text Area Line Number

Quote Reply
Javascript Q. - Text Area Line Number
Does anyone know if it is possible to grab the current line number the cursor is on in a text area box with Javascript?

++++++++++++++++++++++
+ Blah blah black sheep ...
+ have you an[cursor]
+
++++++++++++++++++++++


So in this example... the cursor is on line two of the text area.

I have found examples for the LENGTH of the string in the box, but not anything to do with the part you are currently editing (position of the cursor).

Worst comes to worst, the line number could be calculated by the current legnth of the string divided by the width of the box... but this does not take into account that you could move your cursor to a previous line when editing.


http://www.iuni.com/...tware/web/index.html
Links Plugins

Last edited by:

Ian: Jul 15, 2002, 1:42 PM
Quote Reply
Re: [Ian] Javascript Q. - Text Area Line Number In reply to
My javascript sucks as everyone knows but I've never seen this done. Calculating it some other way my be unreliable if people change the size of the textarea or font.

I'd be interested in seeing a solution..."kode" may come up with something.

Sorry if you were expecting to see an answer :)
Quote Reply
Re: [Paul] Javascript Q. - Text Area Line Number In reply to
Quote:
Sorry if you were expecting to see an answer :)
Yeah, I was... I got all excited tooTongue


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Javascript Q. - Text Area Line Number In reply to
Frown
Quote Reply
Re: [Ian] Javascript Q. - Text Area Line Number In reply to
Okay first attempt:

See attached file scroll2.html

As far as I know IE has some control and Netscape has limited control over the cursor.

as in focus() .

So have a look, maybe it will stir some one's grey matter to think of a way to position the cursor.

Found my example at http://www.faqts.com/...tml/aid/7746/fid/130

Will think on this some more.

Thanks

Kode
Quote Reply
Re: [kode] Javascript Q. - Text Area Line Number In reply to
ooooo, Paul was right, you ARE the javascript guy!

Thanks!

"Arrrg Netscape" is right!

The impetus behind my questioning was to enhance the textareabox in my LinksSQL plug-in editor so I can see what line number I am on when debugging, but also for many other uses.

Excellent job Kode!


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Javascript Q. - Text Area Line Number In reply to
Have been trying a few ways but Netscape may need a java applet.

Found an IE only sample . See Scroll17 attached.

Have a look and see if any use.

Scroll15.html is an IE only way to scroll to a "known" word in a textarea.


Adding : Lots of text / textarea questions/answers at

http://www.faqts.com/.../index.phtml/fid/130

Thanks

Kode

Last edited by:

kode: Jul 15, 2002, 9:33 PM
Quote Reply
Re: [kode] Javascript Q. - Text Area Line Number In reply to
Hmmm, very clever!

I can see the textarea is really an IE object.


http://www.iuni.com/...tware/web/index.html
Links Plugins
Quote Reply
Re: [Ian] Javascript Q. - Text Area Line Number In reply to
Last attempt for now.

See scroll18.html , as you can use a text field vs a text area in Netscape [ tested in NS 6.2 ]

I have placed a style so the border is hidden.

Thus you might use several long text fields instead of 1 Textarea.

[ Too late at night to figure out enter key tabbing down through the text fields ]

You could use the border of a table or div to box in the fake text area.

Oh well a wild attempt at a work around.

Thanks

Kode
Quote Reply
Re: [kode] Javascript Q. - Text Area Line Number In reply to
kode, you are the KING of textareas!

You have been busy there this evening I can see.

Good work!


http://www.iuni.com/...tware/web/index.html
Links Plugins