SitePoint Sponsor

User Tag List

Results 1 to 15 of 15

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    multiple random image scripts on one page - possible??

    using this script http://www.javascriptkit.com/script/cut118.shtml
    can i have more than one in different locations on the same page? nothing i've tried works but i'm no javascript expert....

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes. I'd suggest that you put the function in the header of your page (between the script tags) and then for each occurrence of a random image within your page, enter:

    <script language="JavaScript"><!--
    random_imglink()
    //--></script>


    You'd need to tweak the script a bit if you wanted to make sure that the same image was never chosen twice on the same page.


    Andy
    From the English nation to a US location.

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah, someone else suggested this but it ain't workin yet.... in the page <head> i have this:

    <script language="javascript">
    <!--
    var gallery = new Array();
    var gallery[0] = new Array("01.jpg","02.jpg","03.jpg","04.jpg","05.jpg");
    var gallery[1] = new Array("06.jpg","07.jpg","08.jpg","09.jpg","10.jpg");
    var gallery[2] = new Array("11.jpg","12.jpg","13.jpg","14.jpg","15.jpg");
    var gallery[3] = new Array("16.jpg","17.jpg","18.jpg","19.jpg","20.jpg");
    var gallery[4] = new Array("21.jpg","22.jpg","23.jpg","24.jpg","25.jpg");

    function pickImageFrom(whichGallery){
    var idx = Math.floor(Math.random()*gallery[whichGallery].length);
    document.write('<img src="'images/random/+gallery[whichGallery][idx]+'"');
    }
    //-->
    </script>

    and where i want the images in the page i have this:
    <script language="javascript">pickImageFrom(0);</script>
    <script language="javascript">pickImageFrom(1);</script>
    <script language="javascript">pickImageFrom(2);</script>
    <script language="javascript">pickImageFrom(3);</script>
    <script language="javascript">pickImageFrom(4);</script>

    with what i tried before some of the images would show up and random times (not exactly the kinda random image script i wanted!!) with the broken image thing everywhere else. pretty nasty. with the above code it shows no images, no broken image, not even blank space where the images should be. nada zip zero.

    what i tried before was adding myimage1, myimage2 etc and random_imglink1, random_imglink2 etc. did i need random1, random2 here too:
    var ry=Math.floor(Math.random1()*myimages.length)

    any ideas?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    var gallery = new Array();
    var gallery[0] = new Array("01.jpg","02.jpg","03.jpg","04.jpg","05.jpg");
    ..............
    Here's one suggestion: get rid of those var keywords. You've already declared your array (that one's OK); now you're specifying the elements.
    ::: certified wild guess :::

  5. #5
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's still showing nothing.

  6. #6
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops...(been a long day)...

    document.write('<img src="'images/random/'+gallery[whichGallery][idx]+'">');

    Add the blue, lose the red.
    ::: certified wild guess :::

  7. #7
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that's already there. i copied and pasted just to be sure and still nothing.

    i've been having lots of those longs days lately....like last nite til 3am.

  8. #8
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by amix
    i copied and pasted just to be sure and still nothing.
    Well...not if what you posted here is accurate.

    I really dislike it when people cross-post like this (cross-site, same concept) so, I'll jump ship here. adios
    ::: certified wild guess :::

  9. #9
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    didn't mean to offend anyone on either site. i posted it there first and when i didn't get a reply posted it here the next day. just trying to get it fixed so i can move on to the next thing.... i apologize if i offended you or anyone else.

  10. #10
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No apology necessary, if the above is the case. There have been a rash of people lately who seem to have a macro somewhere that posts the same question to every dev board in the world. I see answers flooding in, while people are toiling to help them diagnose their problem, blissfully unaware that it's been answered already.

    Faggedaboutit. Did you paste in the exact code? Should work.
    ::: certified wild guess :::

  11. #11
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <html>
    <head>
    <title> random.html </title>
    <base href="http://www.how2llc.com/test/">
    <meta name="generator" content="Sausage Software HotDog Professional 6">
    <script language="javascript">
    <!--
    var gallery = new Array();
    	gallery[0] = new Array( "01.jpg","02.jpg","03.jpg","04.jpg","05.jpg");
    	gallery[1] = new Array( "06.jpg","07.jpg","08.jpg","09.jpg","10.jpg");
    	gallery[2] = new Array( "11.jpg","12.jpg","13.jpg","14.jpg","15.jpg");
    	gallery[3] = new Array( "16.jpg","17.jpg","18.jpg","19.jpg","20.jpg");
    	gallery[4] = new Array( "21.jpg","22.jpg","23.jpg","24.jpg","25.jpg");
    
    function pickImageFrom(whichGallery)
    	{
    	var idx = Math.floor(Math.random() * gallery[whichGallery].length);
    	document.write('<img src="images/random/' + gallery[whichGallery][idx] + '">');
    }
    //-->
    </script>
    </head>
    <body>
    <br /><br /><br /><br />
    <div align="center">
    <script language="javascript">pickImageFrom(0);</script><br /><br />
    <script language="javascript">pickImageFrom(1);</script><br /><br />
    <script language="javascript">pickImageFrom(2);</script><br /><br />
    <script language="javascript">pickImageFrom(3);</script><br /><br />
    <script language="javascript">pickImageFrom(4);</script>
    </div><br />
    </body>
    </html>
    ::: certified wild guess :::

  12. #12
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i wouldn't begin to know how to do what you're saying people do, so i guess that let's me out!! i posted it on the other forum mainly because that's where the script came from - figured that was the best place to start. when the answer didn't happen fast enough for me (you know, like 2 hours beFORE i posted it!!), i came here.

    i just uploaded this if it helps to take a look at it: http://www.how2llc.com/test/random.html

  13. #13
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well whatever you did different in the above code, it's working like a charm now. i've been staring at it for so long i couldn't tell what to change, so i copied it into a new random2.html and it works just fine.

    thank you soooooooooooo much for your help!

  14. #14
    SitePoint Wizard silver trophy
    Join Date
    May 2003
    Posts
    1,843
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You're welcome, bad-&#97;&#115;&#115;-mix.
    ::: certified wild guess :::

  15. #15
    SitePoint Enthusiast
    Join Date
    Sep 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm lol'ing over here!! you're taking me back to high school. my born-with initials are b-a-d. a boyfriend gave me an initial ring thinking it was cool and my best friend got me an a-s-s ring to go with it, i guess thinking she was pretty funny. oh well, that was a fun trip down memory lane....

    thanks again.


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
  •