Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Swapping 1

Status
Not open for further replies.

Mighty

Programmer
Feb 22, 2001
1,682
US
There is probably a better way to do this but here is my code:

Code:
function displayProducts()
{
	// Display the last image first
	document.all.productName.innerHTML = products[products.length-1];
	document.all.product.src = "/images/products/" + products[products.length-1] + ".jpg";
	
	
	// Run a continuous loop and change image
	for (i = 0; i < products.length; i++) {
		
	        // Display the current image
		productTimer = window.setInterval("displayProductImage(" + i + ")", 5000)
			
	}

		
}

function displayProductImage(imgNum)
{
	document.all.productName.innerHTML = products[img]um[/img];
	document.all.product.src = "/images/products/" + products[img]um[/img] + ".jpg";
}

On page load I call the displayProducts function. What I want to do is start having my image display the last image in my list and then every 5 seconds switch to the next image in the list but this is not happening. Image swapping is all over the place.

Please help

Mighty
 
document.all is evil. It's Internet Explorer only, won't work in any other browser.

Here's the URL for an image swapping script that I've been using for years:


The automatic slideshow is a bit erratic because of the "free" server scripts that have errors in them, but it can easily be modified to whatever you want.

Lee
 
This illustrates the logic - significantly different from the list which is seriously flawed, apart from the need of id settings of those corresponding element for better cross-browser applicability.
[tt]
function displayProducts()
{
// Display the last image first
var n=products.length-1;
displayProductImage(n);
}

function displayProductImage(imgNum)
{
document.getElementById("productName").innerHTML = products
;
document.getElementById("product").src = "/images/products/" + products
+ ".jpg";

var n=(products.length+imgNum-1) % products.length;
window.setTimeout("displayProductImage("+n+")",5000);
}
[/tt]
 
That's perfect tsuji - thanks.

Mighty
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top