hi all,
i have simple image slideshow script
does anyone know how to do it with a help of for loop
not if
here is code thanks beforehands

<html><head> 
<script type="text/javascript"> 
<!-- 
var image1=new Image() 
image1.src="bir.jpg" 
var image2=new Image() 
image2.src="iki.jpg" 
var image3=new Image() 
image3.src="uc.jpg" 
//--> 
</script> 
</head> 
<body> 
<img src="bir.jpg" name="slide" width="100" height="56" /> 
<script> 
<!-- 
//variable that will increment through the images 
var step=1; 
function slideit(){ 

//if browser does not support the image object, exit. 
if (!document.images) 
return 
document.images.slide.src=eval("image"+step+".src") 
if (step<3) 
step++ 
else 
step=1 
//call function "slideit()" every 2.5 seconds 
setTimeout("slideit()",2500) 
} 
slideit() 
//--> 
</script> 
</body> 
</html>

Something like this maybe :

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">
var images = [];
var imgData = [
	{ src:"bir.jpg", title:"bir"},
	{ src:"iki.jpg", title:"iki" },
	{ src:"uc.jpg",  title:"uc" }
];
//Preload images.
for(var i=0; i<imgData.length; i++ ){
	images[i] = new Image();
	images[i].src = imgData[i].src;
}
function slideit(step){
	step = (!step) ? 0 : step%images.length;
	if (!document.images) { return; }
	document.images.slide.src = imgData[step].src;
	document.images.slide.title = imgData[step].title;
	setTimeout(function(){slideit(step+1)}, 2500);
}
onload = function(){
  slideit();
}
</script>
</head>
<body>
<img src="bir.jpg" title="bir" name="slide" width="100" height="56" />
</body>
</html>

Airshow

Thanks Airshow
it works great but one thing i didnt understand
what is this

step = (!step) ? 0 : step%images.length;

and can you solve one problem if possible
here is url
http://www.daniweb.com/forums/thread266300.html
One thing i would like to say that to this you helped me before if you remember it.
Thanks again for attention

Azegurb,

I thought your name looked familiar. :icon_cool:

step = (!step) ? 0 : step%images.length;

I wondered if you might ask about this line. It does two things. Firstly it defaults step to zero if no parameter is passed into the function, and secondly it effects the required "wrap-around" (back to zero). Read the statement as follows:
If step is undefined, then set step to zero, otherwise set step to the remainder after dividing step by the number of elements in the images array.
I will take a look at your other topic and will help if I can.

Airshow

Thanks very much

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.