How to force a line break using Java Script


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 5 of 5

Thread: How to force a line break using Java Script

  1. #1
    Michael Z. Guest

    How to force a line break using Java Script


    Does anyone know how to force a line break in Text using JavaScript. I know
    that using VBScript "Line1" & Chr(13) & Chr(10) & "Line2" would result in:

    Line1
    Line2

    How do I achieve the same effect in JavaScript.

    Thanks to everybody for help.

  2. #2
    Jim Edgar Guest

    Re: How to force a line break using Java Script

    Michael --

    Try this:

    <html><head>
    <script language=javascript>
    var msg = 'Line1<br>Line2';
    document.write(msg);
    msg = 'Line1\nLine2';
    alert(msg);
    </script>
    </head></html>

    Hope it helps,

    Jim Edgar
    "Michael Z." <yz64@aol.com> wrote in message
    news:3b20361d$1@news.devx.com...
    >
    > Does anyone know how to force a line break in Text using JavaScript. I

    know
    > that using VBScript "Line1" & Chr(13) & Chr(10) & "Line2" would result in:
    >
    > Line1
    > Line2
    >
    > How do I achieve the same effect in JavaScript.
    >
    > Thanks to everybody for help.




  3. #3
    Ben Guest

    Re: How to force a line break using Java Script


    "Jim Edgar" <djedgar@home.com> wrote:
    >Michael --
    >
    >Try this:
    >
    ><html><head>
    ><script language=javascript>
    > var msg = 'Line1<br>Line2';
    > document.write(msg);
    > msg = 'Line1\nLine2';
    > alert(msg);
    ></script>
    ></head></html>
    >
    >Hope it helps,
    >
    >Jim Edgar
    >"Michael Z." <yz64@aol.com> wrote in message
    >news:3b20361d$1@news.devx.com...
    >>
    >> Does anyone know how to force a line break in Text using JavaScript.

    I
    >know
    >> that using VBScript "Line1" & Chr(13) & Chr(10) & "Line2" would result

    in:
    >>
    >> Line1
    >> Line2
    >>
    >> How do I achieve the same effect in JavaScript.
    >>
    >> Thanks to everybody for help.

    >
    >

    also, the escape character "\" plus "n" would do it, e.g.
    alert ('message line one\nmessage line two') would show and alert box:
    message line one
    message line two

  4. #4
    Chris Guest

    Re: How to force a line break using Java Script


    for some reason it only seems to work in an alert if you split the control
    char thus:
    var st = 'line1' + '\n'+ 'Line2';
    alert (st);
    ==========================================
    "Ben" <dorfyben@yahoo.com> wrote:
    >
    >"Jim Edgar" <djedgar@home.com> wrote:
    >>Michael --
    >>
    >>Try this:
    >>
    >><html><head>
    >><script language=javascript>
    >> var msg = 'Line1<br>Line2';
    >> document.write(msg);
    >> msg = 'Line1\nLine2';
    >> alert(msg);
    >></script>
    >></head></html>
    >>
    >>Hope it helps,
    >>
    >>Jim Edgar
    >>"Michael Z." <yz64@aol.com> wrote in message
    >>news:3b20361d$1@news.devx.com...
    >>>
    >>> Does anyone know how to force a line break in Text using JavaScript.


    >I
    >>know
    >>> that using VBScript "Line1" & Chr(13) & Chr(10) & "Line2" would result

    >in:
    >>>
    >>> Line1
    >>> Line2
    >>>
    >>> How do I achieve the same effect in JavaScript.
    >>>
    >>> Thanks to everybody for help.

    >>
    >>

    >also, the escape character "\" plus "n" would do it, e.g.
    >alert ('message line one\nmessage line two') would show and alert box:
    >message line one
    >message line two



  5. #5
    Harold Hunsaker Guest

    Re: How to force a line break using Java Script


    "Michael Z." <yz64@aol.com> wrote:
    >
    >Does anyone know how to force a line break in Text using JavaScript. I

    know
    >that using VBScript "Line1" & Chr(13) & Chr(10) & "Line2" would result in:
    >
    >Line1
    >Line2
    >
    >How do I achieve the same effect in JavaScript.
    >
    >Thanks to everybody for help.


    Michael:

    JS uses escape sequences to control text formatting (taken from the C language).
    One sequence you can use is Line1 + "\n" + Line2. The "\n" escape sequence
    represents the newline (carriage return + linefeed) character.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center