DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   JavaScript / DHTML / AJAX (http://www.daniweb.com/forums/forum117.html)
-   -   Javascript: Go To Line Number (http://www.daniweb.com/forums/thread19556.html)

Comatose Mar 3rd, 2005 1:51 pm
Javascript: Go To Line Number
 
Any idea's about a javascript function, that will move you to specific line number in a textarea? I'm making a mini-page where I can edit text/perl files on a server. I want to be able to plug in the line number that causes the error, hit go, and have the javascript automatically bring me to the line of the file that's loaded in the textarea. If you have any ideas, please, let me know.

tgreer Mar 10th, 2005 11:19 am
Re: Javascript: Go To Line Number
 
No. This is because the contents of a textarea will "flow" based upon screen resolution, browser-window size, etc. Perhaps I'm misunderstanding the situation, if so, please clarify.

Comatose Mar 10th, 2005 1:08 pm
Re: Javascript: Go To Line Number
 
Well, In code, as you well know, there are specific line numbers that may be in question when the program tries to run. The textarea is set to not wrap, so, each line is specified by a line break (most likely \n, but maybe \n\r). Either way, each line of code is specified as such by a newline:
1) sub head
2) {
3)    print header; start_html;
4) }

Now there is an error on line 3 (the ; after header should be a ,), and it would tell me in a log file that line 3 caused this problem. In my web page, I want to have a textbox, and a button (and a textarea). When you type a number into the textbox, and click the button, it should either highlight, or move the cursor (keyboard) to the line number that is represented in the textbox.

I do have a minor solution to this, but it's tacky, and not really what I want. That is, set a variable to 1, and On the keydown event of the textarea, increment the variable, and compare if it is equal to the number in the box, and if so, launch an alert (which stops keyboard activity). so, you could put in say, 30, click the button, click the textarea, and hold down until it stops you with an alert. This is, in my opinion however, a really tacky solution... and I'd rather use something a little more graceful. ;)

tgreer Mar 10th, 2005 1:42 pm
Re: Javascript: Go To Line Number
 
Something like on this page: http://www.nsftools.com/misc/SearchAndHighlight.htm

You have to make extensive use of JavaScript's string functions, such as indexOf, lastIndexof.

Comatose Mar 10th, 2005 5:57 pm
Re: Javascript: Go To Line Number
 
That's EXACTLY what I want, only in a textarea.....but I'd settle just for the cursor going to the textarea.

tgreer Mar 10th, 2005 7:50 pm
Re: Javascript: Go To Line Number
 
I wrote some "setCursorPos" stuff awhile back. Let me search through me archives.


All times are GMT -4. The time now is 10:18 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC