views:

45

answers:

3

I have a <textarea> that I want to print the contents on the page below it. When it does this I want to make random words be omitted.

I have accomplished this. My problem is I want make it recognize when the enter button has been pushed in the <textarea> and display that below. I want those to not ever be omitted. I have gotten it so that when a <br/> is typed into the <textarea> it will not omit those and it will show the new lines. When I tried doing that with the \n it does not seem to recognize in the .value of the object that the enters are \n.

Any ideas how to fix this?

I also tried var txtAdd = document.getElementById('textLoc').value.replace("\n","<br/>"); and it did not work.

A: 

I don't follow what you are trying to do, but is it possible that you need \r\n since that is the equivalent of newline on a windows machine (assuming you are running windows)?

pinkfloydx33
Just tried that out. It did not work.
chromedude
+3  A: 

Maybe ".replace(/\n/g, '<br />');"?

thejh
Possibly `/\r?\n/g` would be better, in case a browser inserts a CR LF sequence.
Pointy
Ah... thanks, didn't think of that option. It works.
chromedude
Ah, it's the crazy old 'replace doesn't actually replace' gotcha/WTF. http://stackoverflow.com/questions/3926610/javascript-jquery-gotchas/3927400#3927400
JulianR
A: 

I think its about way of saving the data first time you should use innerHTML property that you can save it with with out replacing with \n

Regards Marwan