Jump to content

MULTIPLE RANDOM IMAGES WITH LINKS AND TEXT


robbyirish

Recommended Posts

I need some help customising this code..  i know very little about javascript so im hoping you guys can help me out.

 

this script displays a random image with a link, i've customised it  so it displays the text at the bottom of the image as well by adding a new variable and including it in the document.write function

 

the problem i have is i have no idea how to make this script display more than one image at a time without dupicates. please help!!

 

heres the code

 

 

<script language="JavaScript">

 

function random_imglink(){

  var myimages=new Array()

 

  //random images below

  myimages[1]="image1.jpg"

  myimages[2]="image2.jpg"

  myimages[3]="image3.jpg"

 

  //corresponding links below

  var imagelinks=new Array()

  imagelinks[1]="image1 link"

  imagelinks[2]="image2 link"

  imagelinks[3]="image3 link"

 

  //corresponding text below

  var imagetext=new Array()

  imagetext[1]="this is number 1"

  imagetext[2]="this is number 2"

  imagetext[3]="this is number 3"

 

  var ry=Math.floor(Math.random()*myimages.length)

 

  if (ry==0)

    ry=1

    document.write('<a href='+'"'+imagelinks[ry]+'"'+'><img src="'+myimages[ry]+'" border=0><br>'+'"'+imagetext[ry]+'"'+'</a>')

   

}

 

  random_imglink()

//-->

</script>

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.