Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Convert line breaks from plain text into HTML formatted paragraphs

Posted on 2009-05-07
8
Medium Priority
?
438 Views
Last Modified: 2012-05-06
Hi...

How can I convert line breaks from plain text into HTML formatted paragraphs?

For example, if I have a text area field containing plain text with several paragraphs (or line breaks), how can I enclose each paragraph with <p></p> tags?

Then the resulting HTML formatted text would output to another text area field.

Thanks!
0
Comment
Question by:techzzz
8 Comments
 
LVL 41

Assisted Solution

by:HonorGod
HonorGod earned 400 total points
ID: 24330994
use the <pre> tag

for example

<pre>
Now is the time
for all good men
to come to the
aid of their country.
</pre>

Is not reformated.  The end of lines are preserved
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24331004
Does that make sense?

Or, are you asking to convert the user input from a text, or textarea into HTML?

In which case, you want the javascript to surround the value with the <pre> tag for you.

Which is it?
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 24331009
Can you provide a more complete example?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Assisted Solution

by:alien109
alien109 earned 400 total points
ID: 24331029
var text = inputTextField.value;
formattedString = text.replace(/^/mg, "<p>").replace(/$/mg, "</p>");
outputTextfield.value = formattedString;
0
 
LVL 10

Accepted Solution

by:
bugada earned 400 total points
ID: 24331077

var text = document.getElementById("textareaid").value;
text = text.split("\n").join("<p>"); 

Open in new window

0
 

Author Comment

by:techzzz
ID: 24331212
Yes, I want to convert user input from a textarea field, and then output the new code to another textarea field.
0
 
LVL 16

Expert Comment

by:CWS (haripriya)
ID: 37194220
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question