...

View Full Version : Stopping repeated images in array



soulfuel
10-13-2008, 12:55 PM
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>

rnd me
10-13-2008, 02:36 PM
simpler to shuffle the list, then draw from the top.


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());
}
}

soulfuel
10-13-2008, 03:17 PM
Thanks very much, exactly what was needed, a short bit of code that worked a treat.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum