Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-19-2010, 10:20 PM   PM User | #1
sfphoto
New to the CF scene

 
Join Date: Jul 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
sfphoto is an unknown quantity at this point
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>
sfphoto is offline   Reply With Quote
Old 07-19-2010, 10:29 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 07-19-2010, 10:30 PM   PM User | #3
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
sfphoto (07-19-2010)
Old 07-19-2010, 10:41 PM   PM User | #4
sfphoto
New to the CF scene

 
Join Date: Jul 2010
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
sfphoto is an unknown quantity at this point
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!
sfphoto is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:43 AM.


Advertisement
Log in to turn off these ads.