How can I get Javascript to cycle through multiple images?
-
This is what I have so far.. I have played around with this so many times, that I just keeping digging my hole deeper.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml… <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Concert Ads </title> <script type="text/javascript"> <!-- HIDE FROM INCOMPATIBLE BROWERS --> //STOP HIDING FROM INCOMPATIBLE BROWERS --> var curImage="concert1"; var changeImages; function concertAds() { if (curImage == "concert2") { document.images[0].src = "concert1.gif"; curImage = "concert1"; } else { document.images[0].src = "concert2.gif"; curImage = "concert2"; } } </script> </head> <body> <img src="concert1.gif" height="60" width="370" onlick="document.images[0].src='concer… alt="Concert Ads" /> </body> </html>
-
Answer:
First and formost, licking the image on your monitor does nothing...sorry, had to chuckle. (onlick...it is funny) Okay, to your real problem, if you are trying to cycle through images, you can just use an array. Just loop though it somehow, but remember to reset when it gets to the end: <html> <head> <title>Ads</title> <script language='javascript'> function spAds(x){ var sImg = document.getElementById(x.id); adsAr = new Array; var pth = "file:///home/vernon/webs/at_play/"; adsAr[0] = pth + "a.png"; adsAr[1] = pth + "b.png"; adsAr[2] = pth + "c.png"; adsAr[3] = pth + "d.png"; if(adsAr.indexOf(x.src)<3){ sImg.src = adsAr[adsAr.indexOf(x.src) + 1]; } else{ sImg.src = adsAr[0]; } } </script> </head> <body> <img src="a.png"onclick='spAds(this)' id='a' /> </body> </html>
Confused at Yahoo! Answers Visit the source
Related Q & A:
- How can I get rid of the "Get IE7 now!" button on the Yahoo Toolbar?Best solution by Yahoo! Answers
- How can I get an audio alert when I get a new e-mail?Best solution by Yahoo! Answers
- How can I get Bahrain police clearance and were can I apply for it in Australia?Best solution by Yahoo! Answers
- How can I get a text alert when I get an email?Best solution by Yahoo! Answers
- How can I print a picture out on multiple pages?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.