+ Reply to Thread
Results 1 to 8 of 8
  1. #1
    Join Date
    Aug 2010
    Posts
    5

    Unhappy Please Help with my Javascript...

    I need help with my Javascript. I have this script to rotate ads on our website, and it works great. But when I added the 11th image it will not rotate that image but it will still rotate the 1st 10. Can anyone please help me with this so when I add more images with links they will all rotate.

    <br>
    <script type="text/javascript">
    var imgs1 = new Array("/resource/resmgr/Ad_Banner/ad16.jpg","/resource/resmgr/Ad_Banner/ad13.jpg","/resource/resmgr/Ad_Banner/ad14.jpg","/resource/resmgr/Ad_Banner/ad8.jpg","/resource/resmgr/Ad_Banner/ad15.jpg","/resource/resmgr/Ad_Banner/ad18.jpg","/resource/resmgr/Ad_Banner/ad12.jpg","/resource/resmgr/Ad_Banner/ad19.jpg","/resource/resmgr/Ad_Banner/ad20.jpg","/resource/resmgr/Ad_Banner/ad21.jpg","/resource/resmgr/Ad_Banner/ad21.jpg","/resource/resmgr/ad_Banner/ad3.jpg");
    var lnks1 = new Array("http://www.adamscollision.com","http://www.huntleyrealty.com","http://www.trinitycpraed.com","http://www.sccah.com/?page=SCFestival","http://www.blazekshomefurnishings.hdspd.com","http://www.sccah.com/?page=JB_Const","http://tgconsultantsinc.com/","http://blueskiespilotshop.com/index.html ","http://www.aaaglass.com/ ","http://www.carytravelexpress.com/","http://www.sccah.com/?page=Ad_Inquiry ");
    var alt1 = new Array("Adams Collision","Huntley Realty","Trinity","Sun City Arizona","Hunter Douglas Window Coverings and Custom Draperies","J&B Construction","TGI Consulting","Blue Skies","AAA Glass","Cary Travel Express","THIS COULD BE YOUR AD!!!");
    var currentAd1 = 0;
    var imgCt1 = 11;
    function cycle1() {
    if (currentAd1 == imgCt1) {
    currentAd1 = 0;
    }
    var banner1 = document.getElementById('adBanner1');
    var link1 = document.getElementById('adLink1');
    banner1.src=imgs1[currentAd1]
    banner1.alt=alt1[currentAd1]
    document.getElementById('adLink1').href=lnks1[currentAd1]
    currentAd1++;
    }
    window.setInterval("cycle1()",4000);
    </script>
    <a href=""http://www.adamscollision.com"" id="adLink1" target="_blank">
    <img src="/resource/resmgr/Ad_Banner/ad16.jpg" id="adBanner1" border="0" width="170" height="200"></a>

  2. #2
    Join Date
    Jan 2005
    Posts
    436
    Change this var imgCt1 = 11; to this: var imgCt1 = 12;

  3. #3
    Join Date
    Aug 2010
    Posts
    5
    Why 12? if you don't mind me asking. There is only 11 images right now. Should there always be for an example, 11 images var imgCt1 = 12 and 12 images var imgCt1 = 13???

  4. #4
    Join Date
    Aug 2010
    Posts
    5
    It seemed to have worked. Thank you very much for the quick response. I am new to Javascripting, so if I do add more images, let's say 12, am I going to change it to var imgCt1 = 13??

  5. #5
    Join Date
    Jun 2006
    Location
    Florida
    Posts
    327
    var imgs1 contains 12 images. Count 'em.

  6. #6
    Join Date
    Aug 2010
    Posts
    5
    duh, sorry. But now they are all rotating and when the 11th one comes up "Cary Travel Exress" it hangs a little longer then the rest to rotate to the last one. And in doing so if you have your mouse over it to read Cary Travel Express to click to go to there website, when the image first comes up it works great. It says "Cary Travel Express" and you can click and it will take you to there website. But just before it rotates the text when you hover over it changes to the 12th image "THIS COULD BE YOUR AD!!! and if you click it, it will take you to that information page, and when the 12th image finally comes up, it says when you hover "Undefined" and when you click on it, it takes you to an undefined page.

    Do you have any idea as to why it is doing this??? You can go to the website and check it out and see what I am saying. www.sccah.com

  7. #7
    Join Date
    Aug 2010
    Posts
    5
    I think I figured it out. I had the same image in there twice.

  8. #8
    Join Date
    Jan 2005
    Posts
    436
    Because you're using = in the test instead of greater than. That means every time the counter reached 11 previously, it was reset to zero.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts



Latest Headlines from Datamation