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

Discussion in 'Javascript' started by Tamer Higazi, Aug 4, 2007.

  1. Tamer Higazi

    Tamer Higazi Guest

    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
     
    Tamer Higazi, Aug 4, 2007
    #1
    1. Advertising

  2. Tamer Higazi

    Rik Guest

    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
     
    Rik, Aug 4, 2007
    #2
    1. Advertising

  3. Tamer Higazi

    Tamer Higazi Guest

    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
     
    Tamer Higazi, Aug 4, 2007
    #3
  4. Tamer Higazi

    jim Guest

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

    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;
     
    jim, Aug 6, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. MacEgan
    Replies:
    2
    Views:
    364
    Andrew Thompson
    Dec 17, 2005
  2. MacEgan
    Replies:
    1
    Views:
    316
    IchBin
    Dec 17, 2005
  3. Viktor Rosenfeld
    Replies:
    4
    Views:
    1,993
    Viktor Rosenfeld
    Feb 2, 2004
  4. lex __
    Replies:
    3
    Views:
    608
    Neil Cerutti
    Dec 21, 2007
  5. Replies:
    4
    Views:
    135
Loading...

Share This Page