wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes Display of contents from TextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Display of contents from TextArea" Watch "Display of contents from TextArea" New topic
Author

Display of contents from TextArea

Shashank Anand
Greenhorn

Joined: Oct 30, 2008
Posts: 26
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
You need to convert \n to <br>

Eric
Shashank Anand
Greenhorn

Joined: Oct 30, 2008
Posts: 26
I tried this:


and in my html code,

It is not working. Any suggestions please.

-Shashank.

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You should be doing the replace on the server, not the client.

Eric
Austin Tashis
Greenhorn

Joined: May 23, 2003
Posts: 19
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
Austin, it is too late to do it on the client. So the suggestion of document.write will not work.

Eric
 
wood burning stoves
 
subject: Display of contents from TextArea
 
Similar Threads
setting focus to a TextField
Displaying a file contents in TextArea of a GUI
Retrieving formatted text from mysql database
Using CSS font - the text moves to second line
Display UNIX Commands in TextArea