Solved

Convert line breaks from plain text into HTML formatted paragraphs

Posted on 2009-05-07
8
406 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 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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

832 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