image randomizer not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • matt

    image randomizer not working

    I have an image randomizer that was working fine. I added five images to it
    today, and none of the new five are ever called. Here's the script:

    <!-- Begin

    var theImages = new Array()

    theImages[0] = '../pros_stu_pics/prospective2.jp g'
    theImages[1] = '../pros_stu_pics/23x.jpg'
    theImages[2] = '../pros_stu_pics/28xx.jpg'
    theImages[3] = '../pros_stu_pics/15x.jpg'
    theImages[4] = '../pros_stu_pics/16x.jpg'
    theImages[5] = '../pros_stu_pics/24x.jpg'
    theImages[6] = '../pros_stu_pics/gral_info.jpg'
    theImages[7] = '../pros_stu_pics/admit_1.jpg'
    theImages[8] = '../pros_stu_pics/admit_2.jpg'
    theImages[9] = '../pros_stu_pics/admit_3.jpg'
    theImages[10] = '../pros_stu_pics/admit_4.jpg'
    theImages[11] = '../pros_stu_pics/admit_5.jpg'

    var j = 0
    var p = theImages.lengt h;
    var preBuffer = new Array()
    for (i = 0; i < p; i++){
    preBuffer[i] = new Image()
    preBuffer[i].src = theImages[i]
    }
    var whichImage = Math.round(Math .random()*(p-1));
    function showImage(){
    document.write( '<img src="'+theImage s[whichImage]+'">');
    }

    // End -->

    and the call script:

    <!-- Begin
    showImage();
    // End -->

    All of the new files have been uploaded to the right directory. Can anyone
    tell what's wrong?


  • Lee

    #2
    Re: image randomizer not working

    matt said:[color=blue]
    >
    >I have an image randomizer that was working fine. I added five images to it
    >today, and none of the new five are ever called. Here's the script:[/color]

    What do you mean by "are never called"? Do you just always get the
    other pictures, or do you get broken images part of the time?

    The random function you're using will select the first and last
    choice only half as often as the others. It should be:

    var whichImage = Math.floor(Math .random()*p);

    Check the case of the image pathnames.
    "admit1.jpg " would not necessarily be the same as "admit1.JPG "

    Try hard-coding the URLs of your last few images and see if
    the server can find them.

    [color=blue]
    ><!-- Begin
    >
    >var theImages = new Array()
    >
    >theImages[0] = '../pros_stu_pics/prospective2.jp g'
    >theImages[1] = '../pros_stu_pics/23x.jpg'
    >theImages[2] = '../pros_stu_pics/28xx.jpg'
    >theImages[3] = '../pros_stu_pics/15x.jpg'
    >theImages[4] = '../pros_stu_pics/16x.jpg'
    >theImages[5] = '../pros_stu_pics/24x.jpg'
    >theImages[6] = '../pros_stu_pics/gral_info.jpg'
    >theImages[7] = '../pros_stu_pics/admit_1.jpg'
    >theImages[8] = '../pros_stu_pics/admit_2.jpg'
    >theImages[9] = '../pros_stu_pics/admit_3.jpg'
    >theImages[10] = '../pros_stu_pics/admit_4.jpg'
    >theImages[11] = '../pros_stu_pics/admit_5.jpg'
    >
    >var j = 0
    >var p = theImages.lengt h;
    >var preBuffer = new Array()
    >for (i = 0; i < p; i++){
    > preBuffer[i] = new Image()
    > preBuffer[i].src = theImages[i]
    >}
    >var whichImage = Math.round(Math .random()*(p-1));
    >function showImage(){
    >document.write ('<img src="'+theImage s[whichImage]+'">');
    >}
    >
    >// End -->
    >
    >and the call script:
    >
    ><!-- Begin
    >showImage();
    >// End -->
    >
    >All of the new files have been uploaded to the right directory. Can anyone
    >tell what's wrong?
    >
    >[/color]

    Comment

    • matt

      #3
      Re: image randomizer not working

      thanks. i changed the function and it's still not working. by "not calling",
      i mean it just uses the original images. my file names and paths are
      correct. in the opinion of this novice, something is telling it that the
      array is only 7 images long. or something.




      "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
      news:buei0p010u j@drn.newsguy.c om...[color=blue]
      > matt said:[color=green]
      > >
      > >I have an image randomizer that was working fine. I added five images to[/color][/color]
      it[color=blue][color=green]
      > >today, and none of the new five are ever called. Here's the script:[/color]
      >
      > What do you mean by "are never called"? Do you just always get the
      > other pictures, or do you get broken images part of the time?
      >
      > The random function you're using will select the first and last
      > choice only half as often as the others. It should be:
      >
      > var whichImage = Math.floor(Math .random()*p);
      >
      > Check the case of the image pathnames.
      > "admit1.jpg " would not necessarily be the same as "admit1.JPG "
      >
      > Try hard-coding the URLs of your last few images and see if
      > the server can find them.
      >
      >[color=green]
      > ><!-- Begin
      > >
      > >var theImages = new Array()
      > >
      > >theImages[0] = '../pros_stu_pics/prospective2.jp g'
      > >theImages[1] = '../pros_stu_pics/23x.jpg'
      > >theImages[2] = '../pros_stu_pics/28xx.jpg'
      > >theImages[3] = '../pros_stu_pics/15x.jpg'
      > >theImages[4] = '../pros_stu_pics/16x.jpg'
      > >theImages[5] = '../pros_stu_pics/24x.jpg'
      > >theImages[6] = '../pros_stu_pics/gral_info.jpg'
      > >theImages[7] = '../pros_stu_pics/admit_1.jpg'
      > >theImages[8] = '../pros_stu_pics/admit_2.jpg'
      > >theImages[9] = '../pros_stu_pics/admit_3.jpg'
      > >theImages[10] = '../pros_stu_pics/admit_4.jpg'
      > >theImages[11] = '../pros_stu_pics/admit_5.jpg'
      > >
      > >var j = 0
      > >var p = theImages.lengt h;
      > >var preBuffer = new Array()
      > >for (i = 0; i < p; i++){
      > > preBuffer[i] = new Image()
      > > preBuffer[i].src = theImages[i]
      > >}
      > >var whichImage = Math.round(Math .random()*(p-1));
      > >function showImage(){
      > >document.write ('<img src="'+theImage s[whichImage]+'">');
      > >}
      > >
      > >// End -->
      > >
      > >and the call script:
      > >
      > ><!-- Begin
      > >showImage();
      > >// End -->
      > >
      > >All of the new files have been uploaded to the right directory. Can[/color][/color]
      anyone[color=blue][color=green]
      > >tell what's wrong?
      > >
      > >[/color]
      >[/color]


      Comment

      • Simon Wigzell

        #4
        Re: image randomizer not working

        Could this be a caching problem? i.e. your browser is still reading the old
        version of the page. Try CTRL F5 in the browser to force the latest version
        of the page. Put the following in your web page headers to make sure you
        always get the latest version of a webpage :

        <meta HTTP-EQUIV="Expires" CONTENT="0">

        Internet caching is very dumb and lazy, unless explicitly told, it will
        gladly give you the version of the page it is sitting on rather than check
        and see if there is a newer version!



        "matt" <mattburton@hot mail.com> wrote in message
        news:MfOdnVJLxM FyjJbdRVn-jw@comcast.com. ..[color=blue]
        > thanks. i changed the function and it's still not working. by "not[/color]
        calling",[color=blue]
        > i mean it just uses the original images. my file names and paths are
        > correct. in the opinion of this novice, something is telling it that the
        > array is only 7 images long. or something.
        >
        >
        >
        >
        > "Lee" <REM0VElbspamtr ap@cox.net> wrote in message
        > news:buei0p010u j@drn.newsguy.c om...[color=green]
        > > matt said:[color=darkred]
        > > >
        > > >I have an image randomizer that was working fine. I added five images[/color][/color][/color]
        to[color=blue]
        > it[color=green][color=darkred]
        > > >today, and none of the new five are ever called. Here's the script:[/color]
        > >
        > > What do you mean by "are never called"? Do you just always get the
        > > other pictures, or do you get broken images part of the time?
        > >
        > > The random function you're using will select the first and last
        > > choice only half as often as the others. It should be:
        > >
        > > var whichImage = Math.floor(Math .random()*p);
        > >
        > > Check the case of the image pathnames.
        > > "admit1.jpg " would not necessarily be the same as "admit1.JPG "
        > >
        > > Try hard-coding the URLs of your last few images and see if
        > > the server can find them.
        > >
        > >[color=darkred]
        > > ><!-- Begin
        > > >
        > > >var theImages = new Array()
        > > >
        > > >theImages[0] = '../pros_stu_pics/prospective2.jp g'
        > > >theImages[1] = '../pros_stu_pics/23x.jpg'
        > > >theImages[2] = '../pros_stu_pics/28xx.jpg'
        > > >theImages[3] = '../pros_stu_pics/15x.jpg'
        > > >theImages[4] = '../pros_stu_pics/16x.jpg'
        > > >theImages[5] = '../pros_stu_pics/24x.jpg'
        > > >theImages[6] = '../pros_stu_pics/gral_info.jpg'
        > > >theImages[7] = '../pros_stu_pics/admit_1.jpg'
        > > >theImages[8] = '../pros_stu_pics/admit_2.jpg'
        > > >theImages[9] = '../pros_stu_pics/admit_3.jpg'
        > > >theImages[10] = '../pros_stu_pics/admit_4.jpg'
        > > >theImages[11] = '../pros_stu_pics/admit_5.jpg'
        > > >
        > > >var j = 0
        > > >var p = theImages.lengt h;
        > > >var preBuffer = new Array()
        > > >for (i = 0; i < p; i++){
        > > > preBuffer[i] = new Image()
        > > > preBuffer[i].src = theImages[i]
        > > >}
        > > >var whichImage = Math.round(Math .random()*(p-1));
        > > >function showImage(){
        > > >document.write ('<img src="'+theImage s[whichImage]+'">');
        > > >}
        > > >
        > > >// End -->
        > > >
        > > >and the call script:
        > > >
        > > ><!-- Begin
        > > >showImage();
        > > >// End -->
        > > >
        > > >All of the new files have been uploaded to the right directory. Can[/color][/color]
        > anyone[color=green][color=darkred]
        > > >tell what's wrong?
        > > >
        > > >[/color]
        > >[/color]
        >
        >[/color]


        Comment

        • Dr John Stockton

          #5
          Re: image randomizer not working

          JRS: In article <8pGOb.167330$t s4.162314@pd7tw 3no>, seen in
          news:comp.lang. javascript, Simon Wigzell <simonwigzell@s haw.ca> posted
          at Mon, 19 Jan 2004 01:28:36 :-[color=blue]
          >Could this be a caching problem?[/color]

          SW: Please trim your quotes, and put responses after, as per the FAQ and
          Usenet standards.
          [color=blue]
          >"matt" <mattburton@hot mail.com> wrote in message
          >news:MfOdnVJLx MFyjJbdRVn-jw@comcast.com. ..[color=green]
          >> thanks. i changed the function and it's still not working. by "not[/color]
          >calling",[color=green]
          >> i mean it just uses the original images. my file names and paths are
          >> correct. in the opinion of this novice, something is telling it that the
          >> array is only 7 images long. or something.[/color][/color]
          [color=blue][color=green][color=darkred]
          >> > >var theImages = new Array()
          >> > >
          >> > >theImages[0] = '../pros_stu_pics/prospective2.jp g'[/color][/color][/color]
          [color=blue][color=green][color=darkred]
          >> > >theImages[10] = '../pros_stu_pics/admit_4.jpg'
          >> > >theImages[11] = '../pros_stu_pics/admit_5.jpg'[/color][/color][/color]
          [color=blue][color=green][color=darkred]
          >> > >
          >> > >All of the new files have been uploaded to the right directory. Can[/color]
          >> anyone[color=darkred]
          >> > >tell what's wrong?[/color][/color][/color]


          OP: ISTM that you are testing inefficiently, wasting your own time.

          Cease to attempt to fetch the images; instead, display (an alert will
          do) the selected names. Whether the names are right or wrong, the
          problem is halved.

          Don't display the names; display the numbers. Whether the numbers are
          right or wrong, the remaining problem is halved.

          Don't worry about the alleged length of the image array; display it.

          However, apart from the half-probability of the first & last images,
          your code selects properly. Therefore, what you posted is not
          representative, or you tested wrongly.

          --
          © John Stockton, Surrey, UK. ?@merlyn.demon. co.uk Turnpike v4.00 IE 4 ©
          <URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang. javascript
          <URL:http://www.merlyn.demo n.co.uk/js-index.htm> jscr maths, dates, sources.
          <URL:http://www.merlyn.demo n.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

          Comment

          Working...