PDA

View Full Version : Randomize images on refresh



stmal
09-28-2009, 10:14 AM
I want to have 8 image adverts on my web page that change on refresh.

Each one will have bring up a different image when the page is refreshed and it will also have a link to another page.

I have copied part of the script below into a div so that i can place it where i want it on the page, and it works fine (so it changes on refresh and links to another page). But when i try to do a second div next to it with the same script but different image and links it does nothing.

Can anyone tell me how to make make it work more than once.

Thanks in advance


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="BBEdit 7.0.3">
<title>Home page - Company name</title>

<SCRIPT LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">
<!-- Hide script from old browsers

var adImages=new Array()
adImages[0] = "images/4541.jpg"
adImages[1] = "images/47310B-040211-P1.JPG"
adImages[2] = "images/32662.jpg"
adImages[3] = "images/326100-030501-p1.JPG"

var adURL=new Array()
adURL[0] = "4541.html"
adURL[1] = "47310.html"
adURL[2] = "32662.html"
adURL[3] = "326100.html"


var adText=new Array()
adText [0] = "Appraisal, risk management and remedial measures for major rock slopes."
adText [1] = "Design of Remedial meaures to an unstable rail embankment."
adText [2] = "Specialist advice regarding reclamation of a site contaminated by former colliery workings and processing."
adText [3] = "Geotechnical and geoenvironmental advice for proposed city centre development located over two mainline railway tunnels at relatively shallow depth."

thisAd = 0
imgCt = adImages.length
i = 0


function choosePic(targetId) {
if (document.getElementById) {
target = document.getElementById(targetId);
randomNum = Math.floor((Math.random() * imgCt));
target.innerHTML = ("<A HREF='" + adURL[randomNum] + "'><IMG SRC='" + adImages[randomNum] + "' WIDTH='139' HEIGHT='110' NAME='featureBanner' ALT='Ad Banner'><\/a>" + "<span class='adtext'><font face='Gill sans, Helvetica, Verdana, Arial' size='1'>" + adText[randomNum] + "<\/font><\/span>")
}
}


function newLocation() {
parent.internalFrame.document.location.href = " " + adURL[randomNum]
}

// End hiding script from old browsers -->
</SCRIPT>

<!--<style type="text/css" media="screen">
@import url(edgeuk1.css);
</style>//-->

<LINK rel="STYLESHEET" type="text/css" href="edgeuk1.css">
</head>
<body onLoad="choosePic('banner')">

<div id="bannerTitle">
<h1>Images from our Photograph Library</h1>
<div id="banner">

</div>

</body>
</html>