homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / WebmasterWorld / New To Web Development
Forum Library, Charter, Moderators: brotherhood of lan & mack

New To Web Development Forum

Excluding an image from a random list
Javascript Randoms....

10+ Year Member

Msg#: 2054 posted 9:07 am on Mar 23, 2005 (gmt 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~



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

Msg#: 2054 posted 5:51 am on Mar 26, 2005 (gmt 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. :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / New To Web Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved