how do I replace with JS newlines in textareas with <br> ????

T

Tamer Higazi

Hi!
I have a form with a textarea. Now, I don't get it handled to read out
the text, and to replace the (\n) anchor with <br> fields.

As well I want to do the same back, if I call the database entries, to
replace all <br> entries with (\n) entries.

here's the sample code:

var MyString = document.feedbackneu.nachricht.value
MyString.replace(/n/,"<br>");
document.getElementById('ausgabeX').innerHTML = MeinString;


but the output is without newlines.

For any help, thank you


Tamer
 
R

Rik

Hi!
I have a form with a textarea. Now, I don't get it handled to read out
the text, and to replace the (\n) anchor with <br> fields.

As well I want to do the same back, if I call the database entries, to
replace all <br> entries with (\n) entries.

Which is better done on the server IMO.
here's the sample code:

var MyString = document.feedbackneu.nachricht.value
MyString.replace(/n/,"<br>");

Unteste (yes, I'm lazy):
MyString.replace(/\n/,'<br>')?
 
J

jim

You can create text-nodes and use css to format the text without using
<br> tags. If this works for your project just do something like:
stylesheet-excerpt:
p{white-space:pre;}

script-excerpt:
document.getElementsByTagName('p')[0].appendChild(
document.createTextNode( document.feedbackneu.nachricht.value )
);


To do the replacement you'll need to cover all the possible newline
interpretations--and this varies by OS/encoding/browser (maybe other
possibilities too). See http://en.wikipedia.org/wiki/Newline

You could try something like:

var MyString = document.feedbackneu.nachricht.value
MyString.replace(/\n/g,"\n<br />");
document.getElementById('ausgabeX').innerHTML = MeinString;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top