Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.