Andrew2010 Posted November 5, 2010 Share Posted November 5, 2010 I know that the "document.write" section of the code controls all images, but I need to know how do I get it to control just one of each image? function random_imglink(){ var myimages=new Array() //specify random images below. You can have as many as you wish myimages[1]="images/insects/Green Stink Bug.png" myimages[2]="images/insects/Green Stink Bug.png" myimages[3]="images/insects/Green Stink Bug.png" myimages[4]="images/insects/Green Stink Bug.png" myimages[5]="images/insects/Green Stink Bug.png" myimages[6]="images/insects/Bush-Katydid.gif" myimages[7]="images/insects/Bush-Katydid.gif" myimages[8]="images/insects/Bush-Katydid.gif" myimages[9]="images/insects/Bush-Katydid.gif" myimages[7]="images/insects/Common Walkingstick.png" myimages[8]="images/insects/Common Walkingstick.png" myimages[9]="images/insects/Common Walkingstick.png" //specify corresponding links below var imagelinks=new Array() imagelinks[1]="captured.php" imagelinks[2]="captured.php" imagelinks[3]="captured.php" imagelinks[4]="captured.php" imagelinks[5]="captured.php" var ry=Math.floor(Math.random()*myimages.length) if (ry==0) ry=1 document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img style="POSITION: absolute; TOP: 170px; LEFT: 50px" border =0 hspace=0 src="'+myimages[ry]+'" width=70 height=163></a>') } random_imglink() Quote Link to comment https://forums.phpfreaks.com/topic/217797-help-with-small-javascript-function/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.