49 users online (0 members and 49 guests)  


  Results 1 to 4 of 4

Related

  1. Random Image/Member/Forum topic    Forum: PHP Forum
    Replies: 1
  2. random image    Forum: CGI Perl Forum
    Replies: 3
  3. Image problem    Forum: Myspace Forum
    Replies: 1
  4. another image problem    Forum: PHP Forum
    Replies: 9
  5. Replies: 2
  1. #1
    blobb's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    2

    Cool Random Image Problem

    hello,

    i use a simple code below to choose a random image for my site header:

    Code:
    <script language="javascript" type="text/javascript">
    
           p=65*Math.random();
           d=parseInt(p);
           document.write ("<img src ='L:/webroot/pics/"+d+".jpg'>");
    
    </script>
    there are 65 images in the folder, starting from 0.

    all is working pretty wel, but - sometimes it gives a blank result, not the image.

    can You please help?
    thx
    Last edited by vinyl-junkie; 04-16-2007 at 06:02 AM. Reason: Added code tags

  2. #2
    coreybryant's Avatar
    Texan at Heart

    Status
    Offline
    Join Date
    Jun 2003
    Location
    Castle Rock, CO
    Posts
    107

    Re: Random Image Problem

    I'm far from a JS expert but when it does give a blank image, when you right click on the empty space what does the properties say?

    This might help some in determining the problem.

  3. #3
    blobb's Avatar
    New User

    Status
    Offline
    Join Date
    Apr 2007
    Posts
    2

    Re: Random Image Problem

    it shows the properties of the page
    like: "L:/webroot/file.htm"
    so here we see just an empty space

  4. #4
    vinyl-junkie's Avatar
    Moderator

    Status
    Offline
    Join Date
    Sep 2005
    Posts
    721

    Re: Random Image Problem

    Change this statement:

    Code:
    p=65*Math.random();
    to this:

    Code:
    p=Math.floor(65*Math.random());
    For an explanation of why this works, see this page.
    Music Around The World - Collecting tips, trade
    and want lists, album reviews, & more



Tags for this Thread