Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > how do I replace with JS newlines in textareas with <br> ????

Reply
Thread Tools

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

 
 
Tamer Higazi
Guest
Posts: n/a
 
      08-04-2007
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
 
Reply With Quote
 
 
 
 
Rik
Guest
Posts: n/a
 
      08-04-2007
On Sat, 04 Aug 2007 13:22:38 +0200, Tamer Higazi <> wrote:

> 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>')?
--
Rik Wasmus
 
Reply With Quote
 
 
 
 
Tamer Higazi
Guest
Posts: n/a
 
      08-04-2007
didn't work

Rik schrieb:
> On Sat, 04 Aug 2007 13:22:38 +0200, Tamer Higazi <> wrote:
>
>> 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>')?
> --Rik Wasmus

 
Reply With Quote
 
jim
Guest
Posts: n/a
 
      08-06-2007
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-spacere;}

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;

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
replace c-style comments with newlines (regexp) lex __ Python 3 12-21-2007 02:06 PM
Reading information from TextAreas MacEgan Java 2 12-17-2005 11:34 PM
replace all newlines with <br> tags lkrubner@geocities.com Javascript 4 01-30-2005 10:35 PM
F: How can I make re.sub() replace patterns across newlines Viktor Rosenfeld Python 4 02-02-2004 12:59 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57