0

I'm trying to write code that selects a single line of a textarea input. The goal of the site is to provide an input for the user (the textarea) onto which he pastes a log file, and then I want to sort trough the data.

So I've got a textarea and a button below in HTML and don't know what to do from here on...I know the exact line I want to get, but the text length varies from log to log.

Is there a simple JavaScript and HTML solution for this? The select() method supposedly selects the whole content field.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Miha Šušteršič
  • 9,742
  • 25
  • 92
  • 163
  • this would be a start http://stackoverflow.com/questions/1789945/how-can-i-check-if-one-string-contains-another-substring – RST Feb 15 '15 at 09:57
  • and this is the other part http://stackoverflow.com/questions/13650534/how-to-select-line-of-text-in-textarea – ZEE Feb 15 '15 at 10:01
  • Here: http://jsfiddle.net/ztLh8x6n/8/ See consol output... – Matjaž Feb 15 '15 at 10:02
  • You can use `textarea.value.split('\n')` to split it into an array of lines. Then you can index the array to get to the line you want. – Barmar Feb 15 '15 at 10:04
  • @Barmar You can't do that in all cases, because textarea automatically warp word in new lines, without putting `\n` character. – Matjaž Feb 15 '15 at 10:11
  • 1
    @MatjažMav He's talking about a pasted log file, so I assume he wants the original lines from the file, not the displayed lines. – Barmar Feb 15 '15 at 10:12
  • In this case will work :) – Matjaž Feb 15 '15 at 10:24
  • Related: *[How to get range of selected text of textarea in JavaScript](https://stackoverflow.com/questions/12194113/how-to-get-range-of-selected-text-of-textarea-in-javascript/41233895#41233895)* – Peter Mortensen May 09 '22 at 15:57

0 Answers0