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
1
2
3
, and natural new lines (on Enter press) are displayed as normal newlines.

How to do it???

Thnx in advance

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.