View Full Version : Random Image on page load problem

04-02-2005, 01:38 PM
Hello all

I am having errors for some reason for the following script, can anyone help here?

What i want to do is randomize set images in the same location each time the same page is loaded by someone: It's driving me nuts !! The script is:


<script language="javascript">

function imgswp() {
var imgs = new Array("../Banners/0009.jpg","../Banners/0010.jpg","../Banners/0011.jpg","../Banners/0012.jpg")
document.getElementById("aimg").src = imgs[Math.floor(Math.random()*imgs.length)]


<body onLoad="imgswp()">

<div id="top2">
<img border="0" img id="aimg" src="" width="430" height="85" >

04-02-2005, 02:11 PM
Ahhh finally found the problem. All fixed now... :)

04-02-2005, 02:56 PM

To help others!

04-04-2005, 03:44 AM
The problem was seemingly unrelated but vital. The code i used was fine, it was because i had other Javascript on the same page and forgot to seperate it properly in the header ie </script> and start another <script> for the new code.

In my header one set of code referred to a js page and the new code for this randomiser was on the same home page.

A debugger program would have found this for me quicker but i find without it i learn a lot more.