Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stopping repeated images in array

    Hi

    Code below. Similar to a deck of cards, the code displays multiple images in the html from the array in javascript. I am looking for a piece of code that will only allow one instance of the image to be displayed and not repeated in other areas. Does anyone know how to add the code below to make happen?


    var links=new Array();
    links[0]="<a href=javascript:popcontact('angeltemp.htm')><img src='A_New_Dawn.jpg'><br>A NEW DAWN - Click for Detail Card Reading </a> ";
    links[1]="<a href=javascript:popcontact('angeltemp.htm')><img src='Accept_Heavens_Help.jpg'><br>ACCEPT HEAVENS HELP - Click for Detail Card Reading </a> ";
    links[2]="<a href=javascript:popcontact('angeltemp.htm')><img src='Alchemy.jpg'><br>ALCHEMY - Click for Detail Card Reading </a> ";
    links[3]="<a href=javascript:popcontact('angeltemp.htm')><img src='Blessed_Change.jpg'><br>BLESSED CHANGE - Click for Detail Card Reading </a> ";
    links[4]="<a href=javascript:popcontact('angeltemp.htm')><img src='Break_Free.jpg'><br>BREAK FREE - Click for Detail Card Reading </a> ";

    links[5]="<a href=javascript:popcontact('angeltemp.htm')><img src='Consult_an_Expert.jpg'><br>CONSULT AN EXPERT - Click for Detail Card Reading </a> ";
    links[6]="<a href=javascript:popcontact('angeltemp.htm')><img src='Contemplation_Time.jpg'><br>CONTEMPLATION TIME - Click for Detail Card Reading </a> ";
    links[7]="<a href=javascript:popcontact('angeltemp.htm')><img src='Divine_Magic.jpg'><br>DEVINE MAGIC - Click for Detail Card Reading </a> ";
    links[8]="<a href=javascript:popcontact('angeltemp.htm')><img src='Dream_Big.jpg'><br>DREAM BIG - Click for Detail Card Reading </a> ";
    links[9]="<a href=javascript:popcontact('angeltemp.htm')><img src='Empowerment.jpg'><br>EMPOWERMENT - Click for Detail Card Reading </a> ";

    links[10]="<a href=javascript:popcontact('angeltemp.htm')><img src='Explore_Your_Options.jpg'><br>EXPLORE YOUR OPTIONS - Click for Detail Card Reading </a> ";
    links[11]="<a href=javascript:popcontact('angeltemp.htm')><img src='Father_Healing.jpg'><br>FATHER HEALING - Click for Detail Card Reading </a> ";
    links[12]="<a href=javascript:popcontact('angeltemp.htm')><img src='Soulmate_Relationship.jpg'><br>SOULMATE RELATIONSHIP - Click for Detail Card Reading </a> ";
    links[13]="<a href=javascript:popcontact('angeltemp.htm')><img src='Make_a_Wish.jpg'><br>MAKE A WISH! - Click for Detail Card Reading </a> ";
    links[14]="<a href=javascript:popcontact('angeltemp.htm')><img src='Have_Faith.jpg'><br>HAVE FAITH - Click for Detail Card Reading </a> ";



    function disp_links(number) {
    for (i=1;i<=number;i++) {
    var k = Math.floor(Math.random()*links.length);
    document.write(links[k]);
    }
    }


    //The html part here:

    <td class="img"><script type='text/javascript'>disp_links(1);</script></td>
    <td class="img"><script type='text/javascript'>disp_links(1);</script></td>
    <td class="img"><script type='text/javascript'>disp_links(1);</script></td>

  • #2
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,350
    Thanks
    11
    Thanked 589 Times in 570 Posts
    simpler to shuffle the list, then draw from the top.

    Code:
    Array.prototype.shuffle = (function () {function Rnd(w) {return parseInt(Math.random() * (w + 1));};var that = [].concat(this);var mx = that.length;var r = [];var mx2 
    = mx - 1;for (var i = 0; i < mx; i++) {var slot = Rnd(mx2 - i);r[i] = that.splice(slot, 1);}return r;})
    
    var links2 = links.shuffle();
    
    function disp_links(number) {
      for (i=1;i<=number;i++) {
        document.write(links2.pop());
      }
    }
    Last edited by rnd me; 10-13-2008 at 01:43 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #3
    New to the CF scene
    Join Date
    Oct 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks very much, exactly what was needed, a short bit of code that worked a treat.


  •  

    Posting Permissions

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