View Full Version : Random Images

10-07-2006, 12:55 PM
Hi I'm very new to javascript and would like some help.
I'm after a set of code that will display x amount of my images randomly. This code I have and it is working fine. But I would like so that if someone clicks image one.jpg it opens one.htm in target=window.

I have found a site that already has the code, I just cant figure out how to organise and set it up. Here is the site:http://www.vicsjavascripts.org.uk/GroupofRandomImages/GroupofRandomImages.htm

and here is the code I have so far (without the links)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"


<script language="JavaScript" type="text/javascript">
zxccnt=0; zxcta=[];
while (zxccnt<zxca.length){
if (!zxcta[zxctmp]){zxcta[zxctmp]=zxca[zxccnt]; zxccnt++; }
return zxcta;

var ImgPath='http://www.vicsjavascripts.org.uk/StdImages/';
var ImgAry=new Array('Zero.gif','One.gif','Two.gif','Three.gif','Four.gif','Five.gif');

function Display(id){
var ary=[];
var imgs=document.getElementById(id).getElementsByTagName('IMG');
for (var zxc0=0;zxc0<imgs.length;zxc0++){


<body onload="Display('fred');" >
Will work for as many image tags in fred so long as ImgAry has enough images<br>
<a id="fred" >
<img width=100 height=100 >
<img width=100 height=100 >
<img width=100 height=100 >
<img width=100 height=100 >