SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast Wouter's Avatar
    Join Date
    Jan 2002
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question new line char problem

    Why is this new line char not working ?


    <head>

    <script>
    function test()
    { data = 'string1'+'\n'+'string2';
    return (data);}
    </script>

    </head>

    <body>

    <script language="javascript">document.write(test())</script>

    </body>


    Thanks & Greetings

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you want a "javascript new line" or "html new line"?
    Code:
    <html>
      <head>
        <script>
          function test1()
          { 
            data = 'string1'+'\n'+'string2';
            return (data);
          }
          function test2()
          { 
            data = 'string1'+'<br>'+'string2';
            return (data);
          }
        </script>
      </head>
      <body onLoad="alert(test1());document.write(test2());">
      </body>
    </html>

  3. #3
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because '\n' is not valid HTML. That is a newline character recognized by hard returns in a textarea or in Javascript for creating newlines. For example
    Code:
    function test(){ 
    var data = 'string1'+'<br>'+'string2';
    alert(data);
    return data;
    }
    Alerts:
    string1<br>string2
    Returns:
    string1
    string2
    Code:
    function test(){ 
    var data = 'string1'+'\n'+'string2';
    alert (data);
    return data;
    }
    Alerts:
    string1
    string2
    Returns:
    string1 string2
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  4. #4
    SitePoint Enthusiast Wouter's Avatar
    Join Date
    Jan 2002
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    actually I need both - a html and text new line char. Since there's no mutual char I will make it a var in my function.

    Thanks & Greetings -- Belgium


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •