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? As you can see, I need each image to have its OWN set positions. 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() Link to comment https://forums.phpfreaks.com/topic/217881-quick-javascript-function-help/ Share on other sites More sharing options...
Psycho Posted November 5, 2010 Share Posted November 5, 2010 I have no idea what you are asking for. The document.write() doesn't contrl any images - it is simply writing a random image to the page - in a pretty sloppy way. If you need each image on the page in it's own position, just specify the images/layouts in the HTML. Not sure whay you want to achieve with JavaScript. Link to comment https://forums.phpfreaks.com/topic/217881-quick-javascript-function-help/#findComment-1130855 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.