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 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    WA, Australia
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Random Image on page load problem

    Hello all

    I am having errors for some reason for the following script, can anyone help here?

    What i want to do is randomize set images in the same location each time the same page is loaded by someone: It's driving me nuts !! The script is:


    <head>

    <script language="javascript">


    function imgswp() {
    var imgs = new Array("../Banners/0009.jpg","../Banners/0010.jpg","../Banners/0011.jpg","../Banners/0012.jpg")
    document.getElementById("aimg").src = imgs[Math.floor(Math.random()*imgs.length)]
    }
    </script>

    </head>

    <body onLoad="imgswp()">

    <div id="top2">
    <h2>
    <img border="0" img id="aimg" src="" width="430" height="85" >
    </h2></div>
    Last edited by stewb; 04-02-2005 at 02:51 PM.

  • #2
    New Coder
    Join Date
    Dec 2003
    Location
    WA, Australia
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ahhh finally found the problem. All fixed now...

  • #3
    Regular Coder
    Join Date
    Nov 2003
    Location
    Vancouver Island Canada
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts
    How?

    To help others!

  • #4
    New Coder
    Join Date
    Dec 2003
    Location
    WA, Australia
    Posts
    14
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    The problem was seemingly unrelated but vital. The code i used was fine, it was because i had other Javascript on the same page and forgot to seperate it properly in the header ie </script> and start another <script> for the new code.

    In my header one set of code referred to a js page and the new code for this randomiser was on the same home page.

    A debugger program would have found this for me quicker but i find without it i learn a lot more.


  •  

    Posting Permissions

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