View Full Version : Calling more than 1 script

03-17-2004, 07:51 PM

Got a problem, i needed to use a script to randomly select images in a table, which worked fine, until i put my drop down menu on the page as well!!

<script type="text/javascript" language="javascript" src="/java/bg1.js"></script>
<script type="text/javascript" language="javascript" src="/menu/sniffer.js"></script>
<script type="text/javascript" language="javascript1.2" src="/menu/custom.js"></script>
<script type="text/javascript" language="javascript" src="/menu/style.js"></script>
<title>British Rallying.com</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="/styles/master.css" rel="stylesheet" type="text/css">

Top line is the random background, the three lines below are the drop down menu. The menu always works, but the background doesnt, remove the menu lines and then the random script works!

Example Page with Menu (http://www.britishrallying.com/main.html)
Example Page without Menu (http://www.britishrallying.com/main2.html)

The menu also requires a line at the very end of the page to call it into the webpage just before the </body> tag:

<script type="text/javascript" language="javascript1.2" src="/menu/menu.js"></script>
Ive also tried just putting the script for the random image, straight into the page, but still with no luck! :(

Im a bit new at javascript, so hopefully there is an easy answer for this!


Gareth Burrows

Mr J
03-17-2004, 08:20 PM
It could possibly be that the same variable, or variables, are being used in both scripts that is causing a conflict.

Check through them both to see if this is the case

03-17-2004, 08:35 PM
The random image script is as follows:

var arr = new Array("images/bg/color/bgimage4.jpg",

var increment = Math.floor(Math.random() * arr.length);

//pre-load image
var img = new Image();

document.getElementById('main').style.background="white url("+img.src+") no-repeat fixed top"

Would there be another way of loading this script, the menu scripts are to big to post on here!!



03-17-2004, 08:41 PM
it could be possible that there are two window.onload=function()'s ?? thats possibly throwing the error....

03-17-2004, 08:48 PM
If there is, is there any other way round it?

or back to the drawing board!!

03-18-2004, 12:02 AM
I didn't look at it closely, but your answer may be answered in the FAQ sticky (first thread in this forum).