1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Random pictures in each table data cell

Discussion in 'JavaScript and AJAX' started by gilbertsavier, Aug 5, 2009.

  1. gilbertsavier

    gilbertsavier New Member

    Joined:
    Jun 25, 2009
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    0
    Hello, I am new to these forums, and I greet you all

    Here 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!

    Code:
    <script language="javascript">
    
    /*
    Random image slideshow- By Tyler Clarke (EMAIL REMOVED - Send PM to This User Instead)
    For this script and more, visit [url]http://www.javascriptkit.com[/url]
    */
    
    var delay=0 //set delay in miliseconds
    var curindex=0
    
    var 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
    }
    else
    curindex=tempindex
    LnkURL=randomimages[curindex][1];
    document.images.defaultimage.src=randomimages[curindex][0];
    }
    
    setInterval("rotateimage()",delay)
    
    </script>
     
    Last edited by a moderator: Aug 5, 2009
  2. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    Kindly provide your complete code so that you get the proper solution.
    I cannot see 3x3 table, I only got one image object.
     
  3. Saket

    Saket New Member

    Joined:
    Jul 21, 2009
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    Location:
    Don't Know
    Neither I.
     

Share This Page