Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Retaining Line breaks in html:textarea

 
Kannan Somaiah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am currently facing a problem wherein line breaks entered in an <html:textarea> are not retained.

I have two screens. One screen is having a <html:textarea> where the user can enter some details with/without pressing enter key

And in the second screen, whatever details user entered in the textarea will be displayed in an HTML table.

User can navigate between both the screens in any direction. Hope I made my problem clear.

In one of the javaranch posts I found that replacing "\n" with "<br />" will solve the problem. But this does'nt work when I move from screen 2 to screen 1 in my above example.

Please let me know if you have any solution for this.

Regards,
Somaiah
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is correct that a web browser will not render line breaks that are in the source html. So, converting the \n bits into br tags (an html line-break tag) will typically solve the problem. I think line breaks may also be represented with something like \r however.

An even easier solution is to surround the text with a pre tag. The pre tag in HTML tells the browser to output the text exactly as it is with all the extra spaces and line breaks.
 
Kannan Somaiah
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Marc.

I replaced "\n" with "<br />" for HTML presentation and
"\n<br />" with "\n" for displaying it in the textarea. It did the trick.

Though it worked, I wonder why I need to replace "\n<br />" with "\n" when displaying it in an textarea. I am not sure why that extra "\n" came before "<br />"

Regards,
Somaiah
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic