The standard solution is to put the script at the bottom of the body, just before the </body> tag, and to use document.getElementById to access the page element you need.
Thanks for the replies. i have been messing around with the tips you guys provided yet am still having difficulties. what i have (simplified for this exercise) is a
and at the end of my document before the last </body> tag is the linked external javascript file
<script type="text/javascript" src="script-x/HighlightsRandomizer.js"></script>
```html
- written out below is the javascript:
```html
var imagenumber = 9 ;
var randomnumber = Math.random() ;
var rand1 = Math.round( (imagenumber-1) * randomnumber) + 1 ;
images = new Array
images[1] = "../source/RandomAll/images/i1.jpg"
images[2] = "../source/RandomAll/images/i2.jpg"
images[3] = "../source/RandomAll/images/i3.jpg"
images[4] = "../source/RandomAll/images/i4.jpg"
images[5] = "../source/RandomAll/images/i5.jpg"
images[6] = "../source/RandomAll/images/i6.jpg"
images[7] = "../source/RandomAll/images/i7.jpg"
images[8] = "../source/RandomAll/images/i8.jpg"
images[9] = "../source/RandomAll/images/i9.jpg"
var image = images[rand1]
links = new Array
links[1] = "http://www.green.com"
links[2] = "http://www.red.com"
links[3] = "http://www.yellow.com"
links[4] = "http://www.orange.com"
links[5] = "http://www.magenta.com"
links[6] = "http://www.purple.com"
links[7] = "http://www.darkblue.com"
links[8] = "http://www.cyan.com"
links[9] = "http://www.aqua.com"
var link = links[rand1]
document.getElementById("Highlight_1").innerHTML=('<a href="' + link + '"><IMG SRC="' + image + '" border="0"></a>');
i have tried changing the .innerHTML to alert and it pops up the randomizing message after each page reload so i know the randomization code is running, but i still get nothing. help!
kept messing around this morning, finally figured it out. dont know whats different (havnt looked closely yet) but it works! the winning line of code is below: