PDA

View Full Version : Textarea value assigned to Var loses line breaks


tonyeveland
12-05-2002, 06:09 AM
I have a textarea with .... name=address...

Then in a function I have:
var Response = '';
Response = document.forms(0).address.value;


I enter into the textarea:
123 Elm St.
Anytown, Usa

But the Response variable contains:
123 Elm St.Anytown, Usa


My line breaks are gone. Can I get them to stay in the text?

Tony

glenngv
12-05-2002, 06:21 AM
What are you doing in the Response variable?
Are you writing it out like document.write(Response) or setting it in innerHTML like objDiv.innerHTML=Response

In other words, if you are outputting it as HTML, you need to change the \ns to <br>s

Response=Response.replace(/\n/g,'<br>');

btw, the correct usage of "indexing" in an array is by using [] instead of () although I think () is still ok with IE.

document.forms[0].address.value;