Solved

Convert line breaks from plain text into HTML formatted paragraphs

Posted on 2009-05-07
8
415 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 100 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 100 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 100 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

752 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