SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I have a random image script - I'd like to add a caption feature

    Would really appreciate someone's input here please. I have a small piece of Javascript for a random image. I would now like to extend it by adding in a 'caption' feature, so that when the random image is generated, the corresponding caption is also displayed.

    Here's the script:

    Code:
    <script language="JavaScript" type="text/javascript">
    <!-- 
    function random_img(){
    var ranimage = new Array();
    ranimage[1] = "photo1.jpg";
    ranimage[2] = "photo2.jpg";
    ranimage[3] = "photo3.jpg";
    
    var ry = Math.floor(Math.random()*ranimage.length)
    if (ry==0)
    ry=1
    document.write('<img src="'+ranimage[ry]+'" border=1>');
    }
    random_img();
    // -->
    </script>
    So that display a random image. Now, say photo1.jpg is displayed - I would also like a caption for that photo to show up below the photo.

    How do I amend the js so that I can do this?

    Thanks for any help!

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script language="JavaScript" type="text/javascript">
    <!-- 
    function random_img(){
    var ranimage = new Array();
    ranimage[1] = "photo1.jpg";
    ranimage[2] = "photo2.jpg";
    ranimage[3] = "photo3.jpg";
    
    var rantitle = new Array();
    rantitle[1] = "photo1";
    rantitle[2] = "photo2";
    rantitle[3] = "photo3"; 
    
    var ry = Math.floor(Math.random()*ranimage.length)
    if (ry==0)
    ry=1
    document.write('<img src="'+ranimage[ry]+'" border=1><br>'+rantitle[ry]);
    }
    random_img();
    // -->
    </script>
    Saul

  3. #3
    SitePoint Member
    Join Date
    May 2005
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks!


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
  •