943,947 Members | Top Members by Rank

Ad:
Mar 3rd, 2005
0

Javascript: Go To Line Number

Expand Post »
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.
Similar Threads
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Mar 10th, 2005
0

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Mar 10th, 2005
0

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:
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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Mar 10th, 2005
0

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.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004
Mar 10th, 2005
0

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.
Team Colleague
Reputation Points: 361
Solved Threads: 214
Taboo Programmer
Comatose is offline Offline
2,413 posts
since Dec 2004
Mar 10th, 2005
0

Re: Javascript: Go To Line Number

I wrote some "setCursorPos" stuff awhile back. Let me search through me archives.
Team Colleague
Reputation Points: 227
Solved Threads: 37
Made Her Cry
tgreer is offline Offline
1,697 posts
since Dec 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript:How to transfer values between ASP.NET pages
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Javascript making image disappear?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC