Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Display of contents from TextArea

 
Shashank Anand
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a textarea to enter user comments and a html editor toolbar attached to that. The data entered is saved to database and I can retrieve the text, images,hyperlinks etc. But the newline and paragraph and not recognised. I have to display the comments in a paragraph like:

Do you have any idea how to do it (like we post new topic in this forum and it comes out with linebreak and paragraphs.)

Thanks in advance.
Shashank
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to convert \n to <br>

Eric
 
Shashank Anand
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried this:


and in my html code,

It is not working. Any suggestions please.

-Shashank.

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be doing the replace on the server, not the client.

Eric
 
Austin Tashis
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just calling that function from inside a p element won't do the trick. You need to do something with the return value, like document.write() it into the page or, better yet, wait until the document is loaded and set the innerHTML property of the intended document element to the return value.

However, I do agree with Eric. This should be done on the server. If you're storing the text in a database you should be processing it first anyway to prevent SQL injection.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Austin, it is too late to do it on the client. So the suggestion of document.write will not work.

Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic