Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read text line by line in a html text area? [duplicate]

How can I read the contents of a text area line by line or split the text in different lines to obtain input as lines of text.

like image 722
mickeymoon Avatar asked Jul 11 '13 13:07

mickeymoon


People also ask

How do you break a line through text area?

By default, whenever we press “enter” or “shift+enter” it creates a new line in the text area.

How do I display HTML content in textarea?

Complete HTML/CSS Course 2022Use the <textarea> tag to show a text area. The HTML <textarea> tag is used within a form to declare a textarea element - a control that allows the user to input text over multiple rows. Specifies that on page load the text area should automatically get focus.

Does textarea support new line?

To add line breaks to a textarea, use the addition (+) operator and add the \r\n string at the place where you want to add a line break, e.g. 'line one' + '\r\n' + 'line two' . The combination of the \r and \n characters is used as a newline character. Here is the HTML for the examples in this article. Copied!

What is text area in HTML?

This attribute enables you to place <textarea> elements anywhere within a document, not just as descendants of form elements. maxlength. The maximum number of characters (UTF-16 code units) that the user can enter. If this value isn't specified, the user can enter an unlimited number of characters.


4 Answers

You're looking for the Javascript split() method.

like image 99
SLaks Avatar answered Oct 16 '22 20:10

SLaks


Try this one....

you can split by "\n" and then get lilne by line value using for loop

var lines = $('textarea').val().split('\n');
for(var i = 0;i < lines.length;i++){
    //code here using lines[i] which will give you each line
}
like image 40
Ganesh Rengarajan Avatar answered Oct 16 '22 20:10

Ganesh Rengarajan


You can achieve it by using split() method.

 var splittedLines= inputString.split('\n');

And where splittedLines is an array.Loop through splittedLines to get the each line.

like image 23
Suresh Atta Avatar answered Oct 16 '22 19:10

Suresh Atta


var arr = yourtext.split("\n");

loop arr to get each line.

like image 36
anmarti Avatar answered Oct 16 '22 19:10

anmarti