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

    define a path for an image source string

    I want to show multiple images with the same filename except for the numbers on the end. I am trying to define a path for an image source through javascript. Any help would be appreciated. Thanks!

    image filename sample: "http://www.website.com/Azul1.jpg"

    <html>
    <head>

    <script language="Javascript">
    var mypage = "http://www.website.com/Azul"
    document.write(mypage)
    </script>

    </head>

    <center>

    <img src="\'+mypage+\'1.jpg" height="50%">
    <img src="\'+mypage+\'2.jpg" height="50%">
    <img src="\'+mypage+\'3.jpg" height="50%">

    </body>
    </center>
    </html>

  • #2
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Try setting a loop up.

    If you have 10 pictures, and the first picture is numbered "1":

    Code:
    var mypage = "http://www.website.com/Azul";
    
    for (i=1; i < 11; i++) {
    
      document.write(mypage + i);
    
    }

  • #3
    New to the CF scene
    Join Date
    Jun 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Cool. Now how does that fit into the <img src...>?

  • #4
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    While doing this does make it easier to code the page, it will not display the images to any user with javascript enabled, here is the code regardless:

    Code:
    window.onload=function(){
                    for(var i=0;i<10;i++){
                        var img=document.createElement('img');
                        img.setAttribute('src','images/myimage'+i+'.jpg');
                        document.body.appendChild(img);
                    }
                }
    Basscyst
    Helping to build a bigger box. - Adam Matthews


  •  

    Posting Permissions

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