Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert line breaks from plain text into HTML formatted paragraphs

Posted on 2009-05-07
8
Medium Priority
?
426 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…

688 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