How do i get multiple images?

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

Was this solution helpful to you?

Just Added Q & A:

Find solution

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.