SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Scottsdale, AZ
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with array / javascript in firefox

    Hi --

    I'm a bit of a newbie, so please go easy...posted the following script in GoLive to create a page that brings up four random images. It works fine in IE, but not in Firefox. Can anyone help? Thanks!

    Here's the script:

    <script language="JavaScript" type="text/javascript">
    <!--
    var ic = 4;
    var xoxo = new Array(ic);

    xoxo[0] = "[image1].jpg";
    xoxo[1] = "[image2].jpg";
    xoxo[2] = "[image3].jpg";
    xoxo[3] = "[image4].jpg";

    function pickRandom(range) {
    if (Math.random)
    return Math.round(Math.random() * (range-1));
    else {
    var now = new Date();
    return (now.getTime() / 1000) % range;
    }
    }
    var choice = pickRandom(ic);
    </script><SCRIPT LANGUAGE="JavaScript">document.writeln('<TD'+'><IMG SRC="'+xoxo[choice]+'"><'+'/TD>');</SCRIPT>

  2. #2
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this instead:

    xoxo[0] = "image1.jpg";
    xoxo[1] = "image2.jpg";
    xoxo[2] = "image3.jpg";
    xoxo[3] = "image4.jpg";

  3. #3
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Scottsdale, AZ
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    sorry...

    I was misunderstood...the image names were just stand ins...they really don't have the brackets in there. I took out the image names...so that's not the problem. But thanks!

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works in FF for me. When you say it doesn't work in FF, what do you mean? What happens when you try it in FF?

  5. #5
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Scottsdale, AZ
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The image doesn't appear...nothing comes up. Strange...

  6. #6
    SitePoint Member
    Join Date
    Nov 2004
    Location
    Scottsdale, AZ
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sorry -- it looks like it's fixed now! thanks

  7. #7
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    1)Open up the FF javascript console: Tools>Javascript Console
    2) In the Javascript Console, click on Clear.
    3) Load the page in FF.
    4) Look at the Javascript Console and see if it lists any errors.


Bookmarks

Posting Permissions

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