...

View Full Version : Need help with "splashmessages"



caclark
09-24-2003, 04:36 PM
I am trying to create a small "splashmessage" page but I am having trouble with the "num" variable. It will go thru the document.write the first time, but after that I get an error that "num" is undefined.

Any help would be greatly appreciated.

========================================= CODE =========================================

<html>
<head>
<title>Untitled</title>

<script language=javascript>

//configure delay in miliseconds between each message (default: 5 seconds)
var intervals=5000

var splashmessage=new Array()
var openingtags='<center><h1><font face="Arial">'
splashmessage[0]='Message 1 goes here.'
splashmessage[1]='Message 2 Line 1 goes here<br>Message 2 Line 2 goes here'
splashmessage[2]='Message 3 goes here'
var closingtags='</font></h1></center>'
var num=0

function splashMessages() {

if(num<splashmessage.length){
document.write(openingtags+splashmessage[num]+closingtags+"<br>"+num)
num++
document.write("<br>"+num)
}
setTimeout('splashMessages()',intervals)
}

</script>

</head>

<body onLoad="splashMessages()">
<font>Test Text</font>
</body>
</html>

cheesebag
09-24-2003, 04:44 PM
Never call document.write() from an event handler. Period. The results are unpredictable. A loaded document's input stream is closed, and re-opening it is a crapshoot.

Use innerHTML, or DOM (http://www.brainjar.com/dhtml/intro/default4.asp).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum