Javascript: Go To Line Number

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Javascript: Go To Line Number

 
0
  #1
Mar 3rd, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Javascript: Go To Line Number

 
0
  #2
Mar 10th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Javascript: Go To Line Number

 
0
  #3
Mar 10th, 2005
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:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. 1) sub head
  2. 2) {
  3. 3) print header; start_html;
  4. 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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Javascript: Go To Line Number

 
0
  #4
Mar 10th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 2,413
Reputation: Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough Comatose is a jewel in the rough 
Solved Threads: 211
Team Colleague
Comatose's Avatar
Comatose Comatose is offline Offline
Taboo Programmer

Re: Javascript: Go To Line Number

 
0
  #5
Mar 10th, 2005
That's EXACTLY what I want, only in a textarea.....but I'd settle just for the cursor going to the textarea.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 1,655
Reputation: tgreer is an unknown quantity at this point 
Solved Threads: 35
Team Colleague
tgreer tgreer is offline Offline
Made Her Cry

Re: Javascript: Go To Line Number

 
0
  #6
Mar 10th, 2005
I wrote some "setCursorPos" stuff awhile back. Let me search through me archives.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC