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 :)

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Slashdot
  • StumbleUpon
  • Technorati
  • Yahoo! Buzz
Comments (11) Trackbacks (0)
  1. I thought I was being stupid not being able to sort this using but your post saved me a lot of frustration.

    Thanks very much

  2. Thanks Scott. I was just beginning to think I was going to waste ages on a silly problem like this and here’s the solution. Great help.

  3. It’s doesn’t work in IE7…

    Someone else has the same problem ?

  4. Mmmm i am using PHP xajax functions and a jQuery edit in place plugin… I think the Javascript is doing something wrong…

    But you are right…

  5. You saved my sanity here… I was struggling with this for a few hours, during an otherwise busy day, trying to replace linebreaks with tags, tags with linebreaks, etc etc… finally I did the replace you showed (in the PHP str_replace function I had to also discover that single quotes are not the same as double quotes to get the replace to work), and bam… linebreaks in text as they were supposed to be… thanks


Leave a comment

No trackbacks yet.