Sunwins
08-22-2003, 03:33 PM
I'm trying to learn JavaScript from a book (JavaScript Unleashed by Wagner and Wyke).
If I use the this code:
<html>
<head>
<title>hello</title>
</head>
<body onload="PrintText()">
Hello from hello.htm<br>
<script language="JavaScript">
document.write("test 1 of document.write() statement<br>")
</script>
<script language="JavaScript">
function PrintText(){
alert("JavaScript test")
}
</script>
<script language="JavaScript">
document.write("test 2 of document.write() statement<br>");
document.write("test 3 of document.write() statement<br>");
</script>
</body>
</html>
I get a popup box saying "JavaScript test" and the following is printed on the page:
Hello from hello.htm
test 1 of document.write() statement
test 2 of document.write() statement
test 3 of document.write() statement
But, if I change the PrintText function to this:
<script language="JavaScript">
function PrintText(){
document.write("output of PrintText")
}
</script>
Then it briefly prints the text:
Hello from hello.htm
test 1 of document.write() statement
and then clears the screen and prints the text:
output of PrintText
What's causing the screen to be cleared?
If I use the this code:
<html>
<head>
<title>hello</title>
</head>
<body onload="PrintText()">
Hello from hello.htm<br>
<script language="JavaScript">
document.write("test 1 of document.write() statement<br>")
</script>
<script language="JavaScript">
function PrintText(){
alert("JavaScript test")
}
</script>
<script language="JavaScript">
document.write("test 2 of document.write() statement<br>");
document.write("test 3 of document.write() statement<br>");
</script>
</body>
</html>
I get a popup box saying "JavaScript test" and the following is printed on the page:
Hello from hello.htm
test 1 of document.write() statement
test 2 of document.write() statement
test 3 of document.write() statement
But, if I change the PrintText function to this:
<script language="JavaScript">
function PrintText(){
document.write("output of PrintText")
}
</script>
Then it briefly prints the text:
Hello from hello.htm
test 1 of document.write() statement
and then clears the screen and prints the text:
output of PrintText
What's causing the screen to be cleared?