-
I'm using this script to randomly display a menu item. I would like to be able to use this throughout my document with the same array, just a random picture in each place. how could I modify this code to be able to do this? Currently, I'm using the script locally in the body. I would like to have a script in the head of the document and then use the array in different places. Here is the code:
Code:
<script type="text/javascript">
<!--
var imagesArray = new Array(
"image1.gif",
"image2.gif",
"image2.gif"
);
var index = Math.floor(Math.random() * imagesArray.length);
document.write("img src=" + imagesArray[index] + ".");
// -->
</script>
Thanks for any help!!!
-
No takers?????
Nevermind, I figured it out...
Set your array in the head, and then use this code wherever you want the random image:
Code:
<script type="text/javascript">
var index = Math.floor(Math.random() * imagesArray.length);
document.write("img src=" + imagesArray[index] + ".")
</script>
-
cckrocks,
Independance is a beautiful thing, isn't it? ;)