Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a new line in textarea element?

I want to add a newline in a textarea. I tried with \n and <br/> tag but are not working. You can see above the HTML code. Can you help me to insert a newline in a textarea?

<textarea cols='60' rows='8'>This is my statement one.\n This is my statement2</textarea>  <textarea cols='60' rows='8'>This is my statement one.<br/> This is my statement2</textarea> 
like image 592
discky Avatar asked Dec 25 '11 02:12

discky


People also ask

Which character defines a new line in the textarea?

Talking specifically about textareas in web forms, for all textareas, on all platforms, \r\n will work.

How do I preserve line breaks in textarea?

To preserve line breaks when getting text from a textarea with JavaScript, we can replace whitespace characters with '<br>\n' .

How do you add a new line character in HTML?

To add a line break to your HTML code, you use the <br> tag. The <br> tag does not have an end tag. You can also add additional lines between paragraphs by using the <br> tags. Each <br> tag you enter creates another blank line.

How do you enter a line break in code?

To do a line break in HTML, use the <br> tag. Simply place the tag wherever you want to force a line break.


1 Answers

Try this one:

    <textarea cols='60' rows='8'>This is my statement one.&#13;&#10;This is my statement2</textarea>

&#10; Line Feed and &#13; Carriage Return are HTML entitieswikipedia. This way you are actually parsing the new line ("\n") rather than displaying it as text.

like image 157
Bakudan Avatar answered Oct 19 '22 06:10

Bakudan