Jump to content

Deirdreis Dad Please Help


abdelelbouhy
 Share

Recommended Posts

hello guysi'm trying to change image every 5second i've 6 images so here is the code<script type="text/javascript">c =1;function changeimages(){var myImage = document.getElementById("myImage");while(c <= 6){c++;var source = "images/00" + c + ".jpg";myImage.setAttribute('src',source);}var changeTheImages = setInterval("rollimages()",5000);if(c == 6){clearTimeout(changTheImages);}}window.onload = changeimages;</script></head><body><img src="images/001.jpg" widht="200" height="200" id="myImage"/></body></html>but what happend it change only to the last images(images/007.jpg) but when i add an alert to check for example inside the while loop after each alert it chenges the image asi wnated i don't know what is wrong please help

Link to comment
Share on other sites

1. thescientist is correct. Double posting on this board only leads to confusion. Your first post will not get overlooked.2. Your loop is a bad idea. It iterates through all six images IMMEDIATELY. There is no pause. So of course you only see the last image. Try using setInterval to call a function that changes only one image at a time.3. This line has a misspelling: clearTimeout(changTheImages);

Edited by Deirdre's Dad
Link to comment
Share on other sites

1. thescientist is correct. Double posting on this board only leads to confusion. Your first post will not get overlooked.2. Your loop is a bad idea. It iterates through all six images IMMEDIATELY. There is no pause. So of course you only see the last image. Try using setInterval to call a function that changes only one image at a time.3. This line has a misspelling: clearTimeout(changTheImages);
thank you very much deirdre's dad now it's working and so sorry for the double post and i can't find the other post link to report it
Link to comment
Share on other sites

I highly recommend putting a reference to the function on this line:

setInterval("rollimages()",5000);

Like this:

setInterval(rollimages, 5000);

The reason being that the browser doesn't have to run the javascript parser again. Just like eval(), using expressions in quotes is very unefficient. It can go far slower because the browser has to run the parsing engine several times.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...