Replacing <br> with \n for displaying in textarea

S

susikaufmann2003

Hello,

i have a html text, where it is possible (using ajax) to edit the text
by clicking on it. The text is then shown in a textarea. My problem is,
that the newlines are not displayed in the editing textarea. So i tried
to replace the html-<br> with '\n', but it does not work. I only geht
the text without newlines.

I tried:

actual.innerHTML = actual.innerHTML.replace(/<BR>/gi, '\n');
actual.innerHTML = actual.innerHTML.replace(/<BR>/gi, '\\n');

and some more, but it did not work for me :(

Thank you for any help,

Susanne
 
B

Bart Van der Donck

i have a html text, where it is possible (using ajax) to edit the text
by clicking on it. The text is then shown in a textarea. My problem is,
that the newlines are not displayed in the editing textarea. So i tried
to replace the html-<br> with '\n', but it does not work. I only geht
the text without newlines.

I tried:

actual.innerHTML = actual.innerHTML.replace(/<BR>/gi, '\n');
actual.innerHTML = actual.innerHTML.replace(/<BR>/gi, '\\n');

and some more, but it did not work for me :(

You shouldn't populate the textarea using innerHTML. Default form
referencing from script should display the desired result:

<form><textarea name="t"></textarea></form>
<script type="text/javascript">
var content = 'a<br>b<br>c'
document.forms[0].t.value = content.replace(/<br>/gi, '\n');
</script>

Hope this helps,
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top