/    Sign up×
Community /Pin to ProfileBookmark

using setTimeout

I am using the following JS code and cannot get it to work. I am a novice at Javascript. Any help would be appreciated, thanks.

I have one script in the head and one in the body with both using setTimeout but only the script in the body will work. When I use each script seperately they both work.

Here is the code:

<head>

<script language=”JavaScript”>
<!–
// Set up rotating pictures parameters
boardNum=0;
boardSpeed=1000;
billboard=new Array();
billboard[0]=new Image();
billboard[0].src=”pic_1.gif”;
billboard[1]=new Image();
billboard[1].src=”pic_2.gif”;
billboard[2]=new Image();
billboard[2].src=”pic_3.gif”;
billboard[3]=new Image();
billboard[3].src=”pic_4.gif”;
// –>
// Function to rotate pictures
function rotateBoard() {
if (boardNum<billboard.length-1) boardNum++;
else boardNum=0;
document.billboard.src=billboard[boardNum].src;
setTimeout(‘rotateBoard()’,boardSpeed);
}
// –>
</script>

</HEAD>

<Body onLoad=”setTimeout(‘rotateBoard()’,boardSpeed)” >
…blah
…blah
…blah
<SCRIPT LANGUAGE=”JavaScript”>

<!– Begin
var beforeMsg = “<center><font color=blue size=+2><b>”;
var afterMsg = “</b></font></center>”;
var msgRotateSpeed = 5000; // Rotate delay in milliseconds
var textStr = new Array();
textStr[0] = “This is with a 5 second delay!”;
textStr[1] = “Which can be changed to 10 seconds”;
textStr[2] = “Your Events Would be listed here”;
textStr[3] = “Which can be modified and added to”;
if (document.layers) {
document.write(‘<ilayer id=”NS4message” height=25 width=100%><layer id=”NS4message2″ height=25 width=100%></layer></ilayer>’)
temp = ‘document.NS4message.document.NS4message2.document.write(beforeMsg + textStr[i++] + afterMsg);’+
‘document.NS4message.document.NS4message2.document.close()’;
}
else if (document.getElementById) {
document.write(beforeMsg + ‘<div id=”message” style=”position:relative;”>IE division</div>’ + afterMsg);
temp = ‘document.getElementById(“message”).firstChild.nodeValue = textStr[i++];’;
}
else if (document.all) {
document.write(beforeMsg + ‘<div id=”message” style=”position:relative;”>IE division</div>’ + afterMsg);
temp = ‘message.innerHTML = textStr[i++];’;
}
var i = 0;
function msgRotate() {
eval(temp);
if (i == textStr.length) i = 0;
setTimeout(“msgRotate()”, msgRotateSpeed);
}
window.onload = msgRotate;
// End –>
</script>

</body>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@swonJan 25.2003 — Try this:

delete the onLoad Event in the body and set it at the bottom before </body>:

<script language="JavaScript">

<!--

setTimeout('rotateBoard()',boardSpeed)

//-->

</script>

</body>
Copy linkTweet thisAlerts:
@RossauthorJan 25.2003 — Worked like a charm, Thanks very much for the help. It was great.
×

Success!

Help @Ross spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...