AfterGlow
AfterGlow

Reputation: 227

How do you include a linebreak taken from a textarea in a paragraph?

I am using a textarea in my view page to store information in a database, then retrieve it to put in a paragraph. Sometimes I have to include a new line in the textarea, but it is always stored in the database as "a b c", when i retrieve the data to put into a paragraph the new line does not appear. It always shows in a horizontal format like "a b c". How can i show the same style in paragraph format?

Upvotes: 0

Views: 1364

Answers (4)

AsgarAli
AsgarAli

Reputation: 2211

<p id="paragraph">

</p>
<script>
    var ContentFromTextArea = "Your text area content goes here.";
    ContentFromTextArea.replace("\r", "<br />");
    ContentFromTextArea.replace("\n", "<br />");
    $("#paragraph").html(ContentFromTextArea);
</script>

Upvotes: 0

Priyank
Priyank

Reputation: 1384

Use Pre tag to display the data this will consider the line breaks as entered in the textarea you dont need to put textarea inside pre tag as mentioned in the answer of @user3820407

<pre>
 Your Text 
</pre>

see http://www.w3schools.com/tags/tag_pre.asp

Upvotes: 0

mboldt
mboldt

Reputation: 1825

After you read the text from the database and before you show it in the paragraph, you will need to replace the newlines with HTML line breaks.

string text = textFromDatabase.Replace(Environment.NewLine, "<br />");

Upvotes: 3

Dino
Dino

Reputation: 806

Make the textarea wrapped in pre tag

<pre><textarea>CONTENT 
CONTENT
</textarea></pre>

Upvotes: 0

Related Questions