Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 279
  • Last Modified:

Javascript issue

If anyone has a simple answer to this, I would really appreciate it.

<img src="" name="Rotating" id="Rotating1" width=150>
  <img src="" name="Rotating" id="Rotating2" width=150>

   <script type="text/javascript">
       var ImageArr1 = new Array("./FeaturedProducts/1.jpg", "./FeaturedProducts/3.jpg", "./FeaturedProducts/4.jpg");
       var ImageHolder1 = document.getElementById('Rotating1');

       var ImageArr2 = new Array("./FeaturedProducts/6.jpg", "./FeaturedProducts/7.jpg", "./FeaturedProducts/8.jpg");
       var ImageHolder2 = document.getElementById('Rotating2');

       function RotateImages(whichHolder, Start) {
           var a = eval("ImageArr" + whichHolder);
           var b = eval("ImageHolder" + whichHolder);

           if (Start >= a.length)
               Start = 0;
           b.src = a[Start];

//           window.onload("RotateImages(" +  whichHolder + "," + (Start + 1) + ")";

           //window.onload = function (RotateImages)
           window.setTimeout("RotateImages(" + whichHolder + "," + (Start + 1) + ")", 1500);

           
       }

       RotateImages(1, 0);
       RotateImages(2, 0);
 
  </script>


In the code above, instead of do a interval, I would only like it to genate a new photo if the screen is refreshed.
0
kimmie8000
Asked:
kimmie8000
  • 3
  • 2
1 Solution
 
Evan CutlerVolunteer Chief Information OfficerCommented:
I use JQUERY Cycle PLugin.

You can set random to 1, and timeout: 0, in the options.

That should do it for you.  Good in case you change your mind later on.
http://jquery.malsup.com/cycle/
0
 
kimmie8000Author Commented:
Unfortunately, the place the I need to install the code at does not support JQUERY.  Since they are a third party, I cannot install it for them.

I really need to know the answer in javascript, if possible.  I also need to know how to put the "http://" links to the different images, as well.

Thanks!
0
 
Evan CutlerVolunteer Chief Information OfficerCommented:
try this page then.
This guy seems to have nailed it.

http://www.bloke.com/javascript/Random/link.html
0
 
kimmie8000Author Commented:
This is the code you need to get done what I am trying to do... Thanks for any advice given....  

Maybe this will help someone down the road out, if they run into this situation...

It works...  To call this on screen refresh you just add onload (window.onload=RotateImages(1, 1, 0);  So on and so forth!!!

It is quick and dirty, but it gets the job done.  

Make certain your pictures are all the same heigth, as well.
 

 <a href="" name="link" id="link1"><img src="" name="Rotating" id="Rotating1" width="150" /></a>
  <a href="" name="link" id="link2"><img src="" name="Rotating" id="Rotating2" width="150" /></a>
  <a href="" name="link" id="link3"><img src="" name="Rotating" id="Rotating3" width="150" /></a>
  <a href="" name="link" id="link4"><img src="" name="Rotating" id="Rotating4" width="150" /></a>
 

   <script type="text/javascript">
       var ImageArr1 = new Array("./FeaturedProducts/1.jpg", "./FeaturedProducts/3.jpg", "./FeaturedProducts/4.jpg");
       var ImageHolder1 = document.getElementById('Rotating1');
       var linkArr1 = new Array('http://www.google.com/', 'http://www.yahoo.com/', 'http://www.drudgereport.com/');
       var linkHolder1 = document.getElementById('link1');

       var ImageArr2 = new Array("./FeaturedProducts/6.jpg", "./FeaturedProducts/7.jpg", "./FeaturedProducts/8.jpg");
       var ImageHolder2 = document.getElementById('Rotating2');
       var linkArr2 = new Array('http://www.google.com/', 'http://www.yahoo.com/', 'http://www.drudgereport.com/');
       var linkHolder2 = document.getElementById('link2');


       var ImageArr3 = new Array("./FeaturedProducts/9.jpg", "./FeaturedProducts/10.jpg", "./FeaturedProducts/11.jpg");
       var ImageHolder3 = document.getElementById('Rotating3');
       var linkArr3 = new Array('http://www.google.com/', 'http://www.yahoo.com/', 'http://www.drudgereport.com/');
       var linkHolder3 = document.getElementById('link3');


       var ImageArr4 = new Array("./FeaturedProducts/12.jpg", "./FeaturedProducts/13.jpg", "./FeaturedProducts/14.jpg");
       var ImageHolder4 = document.getElementById('Rotating4');
       var linkArr4 = new Array('http://www.google.com/', 'http://www.yahoo.com/', 'http://www.drudgereport.com/');
       var linkHolder4 = document.getElementById('link4');


       function RotateImages(whichHolder, whichLink, Start) {
           var a = eval("ImageArr" + whichHolder);
           var b = eval("ImageHolder" + whichHolder);
           var c = eval("linkArr" + whichLink);
           var d = eval("linkHolder" + whichLink);

         

           if (Start >= a.length)
               Start = 0;
           b.src = a[Start];
           d.href = c[Start];

         

         

           window.setTimeout("RotateImages(" + whichHolder + "," + whichLink + "," + (Start + 1) + ")", 1500);

           
       }

       RotateImages(1, 1, 0);
       RotateImages(2, 2, 0);
       RotateImages(3, 3, 0);
       RotateImages(4, 4, 0);
 
  </script>
0
 
kimmie8000Author Commented:
None of the solutions provided fix my needs. I am at the mercy of a third party software system, which only allows javascript and html for programming.  It is quick and dirty, but it works and it may help someone else down the line.

Thanks!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now