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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jan 2003
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    random image generates Apache errors

    We have a Javascript for generating an image randomnly from a set of images. We are going nuts because even though the script works in that the images display no problem, we are constantly getting the following error messages in our Apache error log (this is just one for pic2.jpg, we see errors for all the pics 1-19):

    [Mon Jan 20 15:03:00 2003] [error] [client 216.119.162.82] File does not exist: /home/httpd/vhosts/sitename.com/httpdocs/pic2.jpg

    We are trying to fiure out why even though the script works, sometime the server thinks the client is trying to fetch the object from the root dir instead of the /images/pictures/ subdirectory (the only place where the pictures are located).

    Here's the script:

    <!-- Begin
    // Set up the image files to be used.
    var theImages = new Array() // do not change this
    // To add more image files, continue with the
    // pattern below, adding to the array.

    theImages[0] = 'pic1.jpg';
    theImages[1] = 'pic2.jpg';
    theImages[2] = 'pic3.jpg';
    theImages[3] = 'pic4.jpg';
    theImages[4] = 'pic5.jpg';
    theImages[5] = 'pic6.jpg';
    theImages[6] = 'pic7.jpg';
    theImages[7] = 'pic8.jpg';
    theImages[8] = 'pic9.jpg';
    theImages[9] = 'pic10.jpg';
    theImages[10] = 'pic11.jpg';
    theImages[11] = 'pic12.jpg';
    theImages[12] = 'pic13.jpg';
    theImages[13] = 'pic14.jpg';
    theImages[14] = 'pic15.jpg';
    theImages[15] = 'pic16.jpg';
    theImages[16] = 'pic17.jpg';
    theImages[17] = 'pic18.jpg';
    theImages[18] = 'pic19.jpg';
    theImages[19] = 'pic20.jpg';

    // do not edit anything below this line

    var j = 0;
    var p = theImages.length;
    var whichImage = Math.round(Math.random()*(p-1));
    function showImage(){
    document.write('<img src="/images/pictures/'+theImages[whichImage]+'" width="180" height="200">');
    }

    // End -->

    We are sure there is no where else on our site that tries to load these pictures. Thanks in advance for any help!

  • #2
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Since it works for you and not for everyone else, maybe your script is not getting evaluated correctly in a certain browser. Have you tested all the common browsers?

    I'm just guessing here, but maybe the quotes and apostrophes in the following line cause a problem in certain browsers.

    Code:
    document.write('<img src="/images/pictures/'+theImages[whichImage]+'" width="180" height="200">');
    I'm bad (TERRIBLE) with OOP, but maybe you want to either

    bring your random number in as a parameter
    Code:
    var whichImage = Math.round(Math.random()*(p-1)); 
    function showImage(whichImage){ 
    document.write('<img src="/images/pictures/'+theImages[whichImage]+'" width="180" height="200">'); 
    }
    or declare your random number inside the function instead of globally
    Code:
    function showImage(){ 
    var whichImage = Math.round(Math.random()*(p-1)); 
    document.write('<img src="/images/pictures/'+theImages[whichImage]+'" width="180" height="200">'); 
    }
    My last two suggestions don't seem like they would fix the problem you're having, so you might want to just ignore them.


  •  

    Posting Permissions

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