Jump to content

Quick Javascript function help


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? 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
Share on other sites

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