gilbertsavier Posted August 7, 2009 Report Share Posted August 7, 2009 Hello, I am new to these forums, and I greet you allHere is the problem I am having. I have a 3x3 table, and I want to use the 6 bottom cells to display linkable pictures of merchandise. I want the cells to display a different picture each time the customer visits the website. I found a javascript for diaplying a random, linkable, picture each time someone visits, but the problem is you can't put the script in each cell. It conflicts with itself somehow. The pictures rotate, but the links only go to the last set of links in the last cell.What is the best method I can use to accomplish my goal? Or can the script below be edited in such a way as to be useable in each cell? Thanks!<script language="javascript">/*Random image slideshow- By Tyler Clarke (EMAIL REMOVED - Send PM to This User Instead)For this script and more, visit http://www.javascriptkit.com*/var delay=0 //set delay in milisecondsvar curindex=0var randomimages=new Array()randomimages[0]=["picturehere.jpg","linkhere"];randomimages[1]=["picturehere.jpg","linkhere"];randomimages[2]=["picturehere.jpg","linkhere"];randomimages[3]=["picturehere.jpg","linkhere"];var preload=new Array()for (n=0;n<randomimages.length;n++){preload[n]=new Image()preload[n].src=randomimages[n]}var First=Math.floor(Math.random()*(randomimages.length));var LnkURL=randomimages[First][1];document.write('<img onclick="Link();" name="defaultimage" src="'+randomimages[First][0]+'">')function Link(){if (LnkURL){window.location=LnkURL;}}function rotateimage(){if (curindex==(tempindex=Math.floor(Math.random()*(randomimages.length)))){curindex=curindex==0? 1 : curindex-1}elsecurindex=tempindexLnkURL=randomimages[curindex][1];document.images.defaultimage.src=randomimages[curindex][0];}setInterval("rotateimage()",delay)</script> Link to comment Share on other sites More sharing options...
justsomeguy Posted August 7, 2009 Report Share Posted August 7, 2009 That's right, every time you paste the code you redefine the randomimages array. Every cell is using the same variables. If you want to use this exact code on more than one place on the same page you'll need to rename everything so the same names aren't used more than once. e.g. for the first cell you would name the variables delay1, curindex1, randomimages1, etc, and the functions Link1 and rotateimage1, then for the second cell you would use delay2, curindex2, etc. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now