Welcome to WebmasterWorld Guest from

Forum Moderators: brotherhood of lan & mack

Message Too Old, No Replies

Excluding an image from a random list

Javascript Randoms....

9:07 am on Mar 23, 2005 (gmt 0)

New User

10+ Year Member

joined:Feb 22, 2005
votes: 0

Here is my Code:

<script language="JavaScript" type="text/javascript">
n=3;// number of all gifs
g=1;//number of random gifs

//no need to modify bellow
var theImages = new Array() //array of gifs
for(var i=0;i<n;i++){
//randomize function
function rand(){
r = Math.floor(Math.random()*n);
return r;
function showImages(){
var rr = new Array()//array of radom numbers
for(var j=0;j<g;j++){
for(var k=0;k<rr.length;k++){//check whether new random number reapets a former one or not
var j=j-1;break
else{rr[j]=r;}//if not, create new array's element
document.getElementById('g'+j).setAttribute('src',theImages[rr[j]]);//set new image
// -->

<a href="#" onclick="showImages();return false">
<IMG SRC="00.gif" ID="g0" ALT="Click to View Your Fortune" BORDER="0"></A>

What I am trying to figure out is how to EXCLUDE the origenal image (00.gif) from being one of the random selections. When the main image is clicked I want it to show a picture from a random list. However I don't want the main image to be in that list. Any comments/suggestions are greatly apreciated. Thanks.

~Isaac Lloyd~

5:51 am on Mar 26, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Dec 9, 2003
votes: 0

Um, quick guess:

for(var i=1;i<n;i++){

ought to do it. If it doesn't, you probably want to post this in the Javascript forum [webmasterworld.com] here. :)