The Infinite Loop – Beginner's SEO, Beginner C# & JQuery Tutorials Problem. Problem Solved. Loop. – The life of a programmer

21Jun/0911

Adding/Insert Line Breaks into a Textarea

Seems like a simple enough problem to solve...just use \n or a br tag
right? ...wrong.
This markup <textarea>Test<br/>Newline</textarea> produces:

And the markup <textarea>Test\nNewline</textarea> produces:

The trick to inserting a new line is to use the character for a carriage return. I stumbled upon this when I ran into this problem. I opened a new notepad file and made a simple textarea. When typing in it, I noticed that when I press enter it goes to a new line (obviously), so I figured why not try to put a carriage return into the textarea. The carriage return representation is &#13; .

So the markup <textarea>Test&#13;Newline</textarea> produces:

And there you have it, simple problem to which the answer may take 30+ minutes to find.
Hopefully I save you that 30 mins :)
Comment, Enjoy :)