| | |
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
![]() |
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.
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:
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.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
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.
•
•
Join Date: Dec 2004
Posts: 1,655
Reputation:
Solved Threads: 35
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.
You have to make extensive use of JavaScript's string functions, such as indexOf, lastIndexof.
![]() |
Similar Threads
- finding line number from a text (C#)
- wxpython textctrl: getting line number (Python)
- JTextPane line number that is in view (Java)
- Displaying error line number (ASP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Javascript:How to transfer values between ASP.NET pages
- Next Thread: Javascript making image disappear?
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxhelp animate array automatically beta box browser bug calendar captchaformproblem cart checkbox child class codes column createrange() css cursor decimal dependent design disablefirebug dom download dropdown editor element engine enter error events explorer ext file firefox focus forms frameworks google gwt highlightedword html htmlform ie8 iframe images index internet java javascript jawascriptruntimeerror jquery jsf jsfile jsp jump listbox masterpage math menu microsoft mimic mp4 object onmouseoutdivproblem onmouseover onreadystatechange parent pdf php player post problem progressbar prototype redirect regex runtime scale scroll search select shopping size sql text textarea toggle w3c web website window windowofwords windowsxp wysiwyg \n






