Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Calling more than 1 script

    Hi,

    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!!

    PHP Code:
    <head>
    <
    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">
    </head> 
    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
    Example Page without Menu

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

    PHP Code:
    <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!

    Regards,

    Gareth Burrows

  • #2
    Senior Coder
    Join Date
    Aug 2002
    Location
    UK
    Posts
    2,789
    Thanks
    2
    Thanked 14 Times in 14 Posts
    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

  • #3
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The random image script is as follows:

    PHP Code:
    var arr = new Array("images/bg/color/bgimage4.jpg",
                
    "images/bg/color/bgimage16.jpg","images/bg/color/bgimage17.jpg","images/bg/color/bgimage18.jpg",
                
    "images/bg/color/bgimage19.jpg","images/bg/color/bgimage20.jpg","images/bg/color/bgimage21.jpg",
                
    "images/bg/color/bgimage22.jpg","images/bg/color/bgimage23.jpg","images/bg/color/bgimage24.jpg",
                
    "images/bg/color/bgimage25.jpg","images/bg/color/bgimage26.jpg","images/bg/color/bgimage27.jpg",
                
    "images/bg/color/bgimage28.jpg","images/bg/color/bgimage29.jpg","images/bg/color/bgimage30.jpg",
                
    "images/bg/color/bgimage31.jpg","images/bg/color/bgimage32.jpg");

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

    //pre-load image
    var img = new Image();
    img.src=arr[increment];

    window.onload=function(){
    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!!

    Cheers

    Gareth

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Manchester, UK
    Posts
    533
    Thanks
    4
    Thanked 1 Time in 1 Post
    it could be possible that there are two window.onload=function()'s ?? thats possibly throwing the error....

  • #5
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    If there is, is there any other way round it?

    or back to the drawing board!!

  • #6
    Senior Coder
    Join Date
    Feb 2004
    Posts
    1,206
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I didn't look at it closely, but your answer may be answered in the FAQ sticky (first thread in this forum).

    Sadiq.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •