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
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Slideshow - location of image files

    Here is a simple slideshow with an on-off button. The images (7 defined) are numbered 01-07.jpg and in the same folder.

    My question. How to call the images from a different folder with the script.

    I can change the <img scr> HTML tag to include a directory where the images are but how do I tell the script?

    Thanks in advance!


    ---page code below---

    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

    <script type="text/javascript">
    var Start = 1
    var Timer3
    function SlideShow()
    {
    if (document.all.ShowButton.value == "Stop Show") {
    clearInterval(Timer3)
    document.all.ShowButton.value = "Start Show"
    } else {
    document.all.ShowButton.value = "Stop Show"
    Timer3 = setInterval("NextPic()" ,3000)
    }
    }
    function NextPic()
    {
    Start += 1
    if (Start > 7) {
    Start = 1
    }
    document.all.Pic.src = "0" + Start + ".jpg"
    }
    </script>

    <body>
    <img id="Pic" src="01.jpg"></p>
    <input id="ShowButton" type="button" value="Start Show" style="font-size:9pt"
    onclick="SlideShow()"/><br>
    </body>

    </html>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Instead of
    Code:
    document.all.Pic.src = "0" + Start + ".jpg";
    you just use
    Code:
    document.all.Pic.src = "yourImageDirectory/0" + Start + ".jpg";
    But...

    But that code will *ONLY* work in MSIE. document.all is an obsolete mechanism left over from MSIE 4 days. MSIE 6 (and I think even 5) and beyond all support the modern standard:
    Code:
    document.getElementById("Pic").src = "yourImageDirectory/0" + Start + ".jpg";
    If you see code still using document.all, you can be pretty sure it is ancient history code that should be avoided.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,506
    Thanks
    77
    Thanked 4,378 Times in 4,343 Posts
    Actually, the fact that you are using
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    pretty much means you aren't going to work with old MSIE browsers, anyway. So why stick with document.all??
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    sfphoto (07-19-2010)

  • #4
    New to the CF scene
    Join Date
    Jul 2010
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    thanks Old Pendant

    That simple line is what I needed. This slide show is small but if large would be great to have all the images in their own directory.

    Thanks!


  •  

    Posting Permissions

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