views:

3906

answers:

6

I got a textarea in javascript but the problem is that when i make line breaks in it they won't display how can i do this ?

i'm getting the value and use a write function but it won't give line breaks

Thanks in advance

A: 

you need to use /n for linebreaks in a textarea

strubester
+1  A: 

A new line is just whitespace to the browser and won't be treated any different to a normal space (" "). To get a new line, you must insert <BR /> elements.

Another attempt to solve the problem: Type the text into the textarea and then add some JavaScript behind a button to convert the invisible characters to something readable and dump the result to a DIV. That will tell you what your browser wants.

Aaron Digulla
A: 

did u tried /n

Shishant
+8  A: 

Problem comes from the fact that line breaks (\n\r?) are not the same as HTML < br /> tags

var text = document.forms[0].txt.value;
text = text.replace(/\n\r?/g, '<br />');
TStamper
THANK YOU VERY MUCH THIS SOLVED MY PROBLEM
djairo
This works for me too. In jQuery you can do something like this: $('#caption').html($('#caption').text().replace(/\n\r?/g, '<br />'));
DavGarcia
A: 

How would this work serverside? using this I get an error

var text = Request.Form("test") text = text.replace(/\n\r?/g, '
');

Microsoft JScript runtime error '800a01b6'

Object doesn't support this property or method

J_D
A: 

thanks for this

.replace(/\n\r?/g, '<br />');
Ryan