Web Analytics Made Easy -
StatCounter Absolute beginner - CodingForum

Announcement

Collapse
No announcement yet.

Absolute beginner

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Absolute beginner

    Hi all.

    Have literally just begin to look at JavaScript and am just past the "Hello World" stage and have encountered a problem.

    I have the code:

    <html>
    <head>Test</head>
    <body>
    <script language="JavaScript">
    document.write("No line after this")
    document.writeln("A line after this")
    document.write("No line after this")
    </script>
    </body>
    </html>

    When I browse the html file I get the output:

    No line after thisA line after thisNo line after this

    without the line break I expected from the .writeln method.

    Can someone please tell me what I'm doing wrong here.

    Thanks in advance.

    Russell.

  • #2
    <html>
    <head></head>
    <body>
    Test
    <script language="JavaScript">
    document.write("No line after this")
    document.write("A line after this<br>")
    document.write("No line after this")
    </script>
    </body>
    </html>
    Last edited by Graeme Hackston; Jun 26, 2002, 12:14 AM.

    Comment


    • #3
      Resulting source code vs rendered HTML

      Dave.

      Thanks for your email.

      I'm not sure if I do understand the distinction.

      More explicitly, I guess, I don't understand what the "resulting source code" in fact is.

      My html file reads the same to me whether I look at it using Notepad or browse it as an HTML document using IE.

      Under what conditions would I want to use document.writeln() if <br> is required to give me a new line on a browsed page?

      Thanks again.

      Russell.

      Comment


      • #4
        Re: Absolute beginner

        The resulting source code for this:

        <html>
        <head>Test</head>
        <body>
        <script language="JavaScript">
        document.write("No line after this")
        document.writeln("A line after this")
        document.write("No line after this")
        </script>
        </body>
        </html>

        is:

        <html>
        <head>Test</head>
        <body>
        No line after thisA line after this
        No line after this
        </script>
        </body>
        </html>

        The rendered HTML is:

        No line after thisA line after thisNo line after this


        While the resulting code for this:

        <html>
        <head></head>
        <body>
        Test
        <script language="JavaScript">
        document.write("No line after this")
        document.write("A line after this<br>")
        document.write("No line after this")
        </script>
        </body>
        </html>

        is:

        <html>
        <head></head>
        <body>
        Test
        No line after thisA line after this<br>No line after this
        </script>
        </body>
        </html>

        The rendered HTML is:

        No line after thisA line after this
        No line after this


        The resulting source code is the HTML source generated. Code generated by document.write's are not shown when you click View-Source in the browser, but internally it generated the output discussed above.
        Rendered HTML is the generated output when the browser interprets the resulting source code.

        Hope I discussed it clearly.

        Do you see the distinction now?
        Glenn
        vBulletin Mods That Rock!

        Comment


        • #5
          Resulting source code vs rendered HTML

          Glenn.

          I understand the distinction now. Thanks for your very clear explanation.

          Regards,

          Russell.

          Comment


          • #6
            Actual source

            Dave.

            Thanks again - that's great.

            Regards,

            Russell.

            Comment

            Working...
            X