Allan- Posted December 23, 2008 Share Posted December 23, 2008 I want to change image src after some time to another (after 3 secs in example) and if there arent more images then turn into the first one again. In example I have 3 different image sources (gfx/img1.jpg, gfx/img2.jpg, gfx/img3.jpg). This is part of my code but something is wrong there. Can someone help? <script type="text/javascript"> var i = 0; var image = document.getElementById('changeimage'); function changeImage() { if (i == 0) { image.src = 'gfx/img1.jpg'; i = 1; } else if (i == 1) { image.src = 'gfx/img2.jpg'; i = 2; } else { image.src = 'gfx/img3.jpg'; i = 0; } setTimeout('changeImage()', 3000); } </script> </head> <body onload="changeImage();"> <img id="changeimage" src="gfx/img1.jpg" /> Link to comment https://forums.phpfreaks.com/topic/138159-solved-change-image-after-some-time/ Share on other sites More sharing options...
Adam Posted December 23, 2008 Share Posted December 23, 2008 What error do you get in Firefox's error console? I don't think you can create an object like this outside of a function: var image = document.getElementById('changeimage'); Try adding it inside the function.. A Link to comment https://forums.phpfreaks.com/topic/138159-solved-change-image-after-some-time/#findComment-722412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.