View Full Version : Absolute beginner
rah111
06-26-2002, 04:59 AM
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.
Graeme Hackston
06-26-2002, 05:10 AM
<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>
rah111
06-26-2002, 05:55 AM
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.
glenngv
06-26-2002, 06:40 AM
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?
rah111
06-26-2002, 06:54 AM
Glenn.
I understand the distinction now. Thanks for your very clear explanation.
Regards,
Russell.
rah111
06-26-2002, 02:31 PM
Dave.
Thanks again - that's great.
Regards,
Russell.
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.