javascript question
- Started
- Last post
- 4 Responses
- xrusos
i'm working with a simple image rotate script that includes a script in the head tag, and then calls it from the body.
only deal is that i want to move the script to a .js file and call it instead of having it written out at the top of the page.
unfortunately it won't work when i do that. can you help?
i'll post the script next.
- xrusos0
here's the image rotate script contained within script tags in the head... (that i want to move to a .js file)
// JavaScript to interpolate random images into a page.
var ic = 11; // Number of alternative images
var xoxo = new Array(ic); // Array to hold filenamesxoxo[0] = "/images/highlanders.jpg";
xoxo[1] = "/images/car.jpg";
xoxo[2] = "/images/broken_dock.jpg";
xoxo[3] = "/images/lighthouse.jpg";
xoxo[4] = "/images/bird.jpg";
xoxo[5] = "/images/red_barn.jpg";
xoxo[6] = "/images/deck.jpg";
xoxo[7] = "/images/fog.jpg";
xoxo[8] = "/images/subway.jpg";
xoxo[9] = "/images/highlanders.jpg";
xoxo[10] = "/images/highlanders.jpg";function pickRandom(range) {
if (Math.random)
return Math.round(Math.random() * (range-1));
else {
var now = new Date();
return (now.getTime() / 1000) % range;
}
}
// Write out an IMG tag, using a randomly-chosen image name.
var choice = pickRandom(ic);
// -->
- xrusos0
and here's the script that calls the first script from within the layout:
[SCRIPT LANGUAGE="JavaScript"]document.w... SRC="'+xoxo[choice]+'" HEIGHT=200 WIDTH=552 BORDER=0 >');[/SCRIPT]
- xrusos0
so i think it has something to do with the last bit of code...
document.writeIn
i'm assuming something there tells it where to look for the script. how can i tell it to look for a .js file instead of to the top of the page?
- xrusos0
hoping for an answer still, so bump.