Forum Moderators: mack
<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++){
theImages[i]='0'+i+'.gif';
}
//randomize function
function rand(){
r = Math.floor(Math.random()*n);
return r;
}
function showImages(){
var rr = new Array()//array of radom numbers
rr[0]=-1;
for(var j=0;j<g;j++){
rand();
for(var k=0;k<rr.length;k++){//check whether new random number reapets a former one or not
if(k!=j&&r==rr[k]){
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
}
}
// -->
</script>
<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~
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. :)