Click here to Skip to main content
15,886,518 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
hey guys,

just wanna ask if how can I automatically change the image into random images i stored after 30 seconds. Thanks in advance. im using visual studio, html5, javascript.
Posted
Comments
Pheonyx 28-Nov-13 10:28am    
What have you tried?
Are you using an MVC approach?
Member 10302214 28-Nov-13 10:30am    
i tried this, but still it is not changing:

var images = []
images[0] = "pics/1.jpg";
images[1] = "pics/2.jpg";
images[2] = "pics/3.jpg";
images[3] = "pics/4.jpg";
images[4] = "pics/5.jpg";
setInterval("changeImage()", 30000);
var x = 0;
function changeImage(every_seconds) {
if (x < 5) {
document.getElementById("pics").src = images[x]
x++;
}
if (x == 5) x = 0;
}
Sergey Alexandrovich Kryukov 28-Nov-13 11:48am    
It should not work. You need to show a different image in each timer event. And you don't have a random choice of an image...
—SA
vbmike 28-Nov-13 21:06pm    
You need a random selection process like this --
var x=Math.floor(Math.random()*images.length)--
See where that gets you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900