Jump to content

Help with small Javascript function


Andrew2010

Recommended Posts

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()

Link to comment
https://forums.phpfreaks.com/topic/217797-help-with-small-javascript-function/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.