I have a <textarea> and <button>. When button is pressed the text entered in textarea will be displayed inside of <p></p>.

So I want: when I enter for instance "1<br>2<br>3" in textarea and press button, exactly the same text is displayed in <p> i.e. "1<br>2<br>3" is displayed instead of
, and natural new lines (on Enter press) are displayed as normal newlines.

How to do it???

Thnx in advance

6 Years
Discussion Span
Last Post by drjohn

You'd have to use the html entities instead of the < and >
eg 1&lt;br&gt;2&lt;br&gt;3&lt;br&gt;
which the browser will then display as 1<br>2<br>3<br>

&lt; means the less then symbol, <
&gt; means the great than symbol, >

to get a new line from pressing the enter key, you'd have to use a PHP function, nl2br(), to process the data entered. It turns a new line into a <br> tag.

You could of course write a script which did a search and replace on < and > to change then to the required entities, which might be much more convenient as you'd be less likely to have a typo in the data in your textbox. So the script would process the <s and >s first, then the output would be passed to the nl2br() function

Edited by drjohn: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.