0

Can anyone help me with this code. There are 11 images now. When it was running just 10 it was working fine, but when I added the 11th it won't rotate the 11th but will still rotate the first 10.

<br>
<script type="text/javascript">
var imgs1 = new Array("/resource/resmgr/Ad_Banner/ad16.jpg","/resource/resmgr/Ad_Banner/ad13.jpg","/resource/resmgr/Ad_Banner/ad14.jpg","/resource/resmgr/Ad_Banner/ad8.jpg","/resource/resmgr/Ad_Banner/ad15.jpg","/resource/resmgr/Ad_Banner/ad18.jpg","/resource/resmgr/Ad_Banner/ad12.jpg","/resource/resmgr/Ad_Banner/ad19.jpg","/resource/resmgr/Ad_Banner/ad20.jpg","/resource/resmgr/Ad_Banner/ad21.jpg","/resource/resmgr/Ad_Banner/ad21.jpg","/resource/resmgr/ad_Banner/ad3.jpg");
var lnks1 = new Array("http://www.adamscollision.com","http://www.huntleyrealty.com","http://www.trinitycpraed.com","http://www.sccah.com/?page=SCFestival","http://www.blazekshomefurnishings.hdspd.com","http://www.sccah.com/?page=JB_Const","http://tgconsultantsinc.com/","http://blueskiespilotshop.com/index.html ","http://www.aaaglass.com/ ","http://www.carytravelexpress.com/","http://www.sccah.com/?page=Ad_Inquiry ");
var alt1 = new Array("Adams Collision","Huntley Realty","Trinity","Sun City Arizona","Hunter Douglas Window Coverings and Custom Draperies","J&B Construction","TGI Consulting","Blue Skies","AAA Glass","Cary Travel Express","THIS COULD BE YOUR AD!!!");
var currentAd1 = 0;
var imgCt1 = 11;
function cycle1() {
if (currentAd1 == imgCt1) {
currentAd1 = 0;
}
var banner1 = document.getElementById('adBanner1');
var link1 = document.getElementById('adLink1');
banner1.src=imgs1[currentAd1]
banner1.alt=alt1[currentAd1]
document.getElementById('adLink1').href=lnks1[currentAd1]
currentAd1++;
}
window.setInterval("cycle1()",4000);
</script>
<a href=""http://www.adamscollision.com"" id="adLink1" target="_blank">
<img src="/resource/resmgr/Ad_Banner/ad16.jpg" id="adBanner1" border="0" width="170" height="200"></a>

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by gumape
0

you have:
12 items in imgs1
11 items in lnks1
11 items in alt1

Make them all the same number of items.

0

I have done some modifications in your code to become more readable and usable.
Hielo has right, you have an additional item (/resource/resmgr/ad_Banner/ad3.jpg) in imgs1, I have removed it:

<head>
	<script type="text/javascript">
		var imgDatas = [
			{src: "/resource/resmgr/Ad_Banner/ad16.jpg", href: "http://www.adamscollision.com", alt: "Adams Collision"},
			{src: "/resource/resmgr/Ad_Banner/ad13.jpg", href: "http://www.huntleyrealty.com", alt: "Huntley Realty"},
			{src: "/resource/resmgr/Ad_Banner/ad14.jpg", href: "http://www.trinitycpraed.com", alt: "Trinity"},
			{src: "/resource/resmgr/Ad_Banner/ad8.jpg", href: "http://www.sccah.com/?page=SCFestival", alt: "Sun City Arizona"},
			{src: "/resource/resmgr/Ad_Banner/ad15.jpg", href: "http://www.blazekshomefurnishings.hdspd.com", alt: "Hunter Douglas Window Coverings and Custom Draperies"},
			{src: "/resource/resmgr/Ad_Banner/ad18.jpg", href: "http://www.sccah.com/?page=JB_Const", alt: "J&B Construction"},
			{src: "/resource/resmgr/Ad_Banner/ad12.jpg", href: "http://tgconsultantsinc.com/", alt: "TGI Consulting"},
			{src: "/resource/resmgr/Ad_Banner/ad19.jpg", href: "http://blueskiespilotshop.com/index.html ", alt: "Blue Skies"},
			{src: "/resource/resmgr/Ad_Banner/ad20.jpg", href: "http://www.aaaglass.com/ ", alt: "AAA Glass"},
			{src: "/resource/resmgr/Ad_Banner/ad21.jpg", href: "http://www.carytravelexpress.com/", alt: "Cary Travel Express"},
			{src: "/resource/resmgr/Ad_Banner/ad21.jpg", href: "http://www.sccah.com/?page=Ad_Inquiry", alt: "THIS COULD BE YOUR AD!!!"}
		];

		var currentAd = -1;

		function cycle () {
			currentAd = (currentAd + 1) % imgDatas.length;

			var banner1 = document.getElementById('adBanner1');
			var link1 = document.getElementById('adLink1');

			banner1.src = imgDatas[currentAd].src;
			banner1.alt = imgDatas[currentAd].alt;
			link1.href = imgDatas[currentAd].href;
		}

		function Init () {
			cycle ();
			window.setInterval (cycle, 4000);
		}
	</script>
</head>
<body onload="Init ()">
	<a href="" id="adLink1" target="_blank">
	<img src="" id="adBanner1" border="0" width="170" height="200"></a> 
</body>

I think the following links will be useful for you:
Array object, associative arrays,
onload event,
setInterval method.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.