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>
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>