Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to show newlines from textarea in a table?

In a form I have a textarea where obviously text is entered. When the input is finished the content gets submitted to the server and is being stored in a database...

When I display the input the user made within a table, the newlines are not visible. When I inspect the source the newlines are there, but within a table the newlines do not work...

Is there any possibility of displaying the linebreaks within that table? I know, probably a really silly question but I'm not to pro when it comes to things like html and css...

Any help is really appreciated!

like image 306
Gnark Avatar asked Sep 24 '09 09:09

Gnark


People also ask

How do you show data on the next line?

On Windows operating system, use Alt + Enter for a line break.

How do I preserve line breaks when getting text from a textarea?

Preserve Newlines, Line Breaks, and Whitespace in HTML If you want your text to overflow the parent's boundaries, you should use pre as your CSS whitespace property. Using white-space: pre wraps still preserves newlines and spaces. Enjoy!

How do you go to next line in textarea?

Press "enter" to submit and "shift+enter" to generate a new line. How to add line breaks to an HTML textarea?

How do I show multiple lines of text in HTML?

Complete HTML/CSS Course 2022 To create a multi-line text input, use the HTML <textarea> tag. You can set the size of a text area using the cols and rows attributes. It is used within a form, to allow users to input text over multiple rows.


2 Answers

Set your css in the table cell to

white-space:pre-wrap;
like image 130
vsync Avatar answered Oct 20 '22 22:10

vsync


\n won't be rendered as a new line in HTML. You have to use a <br/> to achieve this effect.

Use a string replace to replace all '\n' characters to '<br/>'

If you are using a server side language like C# you can do this

private string PutLineBreaks(string strData)
{
    string strReplaced = string.Empty;

    Regex r = new Regex("/\n/g");

    strReplaced = r.Replace(strData, "<br/>");

    return strReplaced;
}
like image 26
rahul Avatar answered Oct 21 '22 00:10

rahul