Convert line breaks from plain text into HTML formatted paragraphs

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!
techzzzAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
bugadaConnect With a Mentor Commented:

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

Open in new window

0
 
HonorGodConnect With a Mentor Commented:
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
 
HonorGodCommented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
HonorGodCommented:
Can you provide a more complete example?
0
 
alien109Connect With a Mentor Commented:
var text = inputTextField.value;
formattedString = text.replace(/^/mg, "<p>").replace(/$/mg, "</p>");
outputTextfield.value = formattedString;
0
 
techzzzAuthor Commented:
Yes, I want to convert user input from a textarea field, and then output the new code to another textarea field.
0
 
CWS (haripriya)Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.