Forum Moderators: open

Message Too Old, No Replies

random image display (source debugging)

         

logikal

7:56 pm on Jan 17, 2004 (gmt 0)

10+ Year Member



hey,
here's my goal: to randomly pick and display one of 3 photos (001.jpg, 002.jpg, or 003.jpg). can anyone see what's wrong with the sources below to make it not work? Thanks in advance...

[in header]
<script language="JavaScript1.2" src='/image.js'></script>

[in body]
<script language="JavaScript1.2">
RandomImage();
</script>

[in image.js]
image_list = [001,002,003];
image_num = Math.floor(Math.random() * image_list.length() );

function RandomImage() {
document.write('<img width=400 height=218 src=" + image_list[image_num] + ".jpg>');
}

birdbrain

10:48 pm on Jan 17, 2004 (gmt 0)



Hi there logikal,

Your image.js should look like this...


<!--
image_list = new Array('001','002','003');
image_num = Math.floor(Math.random()*image_list.length);
//-->

...and the body like this...

<body>
<script type="text/javascript">
<!--
document.write('<img width=400 height=218 src='+image_list[image_num] + '.jpg>');
//-->
</script>
</body.

birdbrain

logikal

11:18 pm on Jan 17, 2004 (gmt 0)

10+ Year Member



Works like a charm, thanks a lot man

I just had some issues with the ' and "s

loGikaL

birdbrain

11:38 pm on Jan 17, 2004 (gmt 0)



Hi there logikal,

No problem, you're welcome.

birdbrain