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.
By default, whenever we press “enter” or “shift+enter” it creates a new line in the text area.
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.
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!
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.
You're looking for the Javascript split()
method.
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
}
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.
var arr = yourtext.split("\n");
loop arr to get each line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With