Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image Slideshow from database 1

Status
Not open for further replies.

Lambro

Programmer
Aug 22, 2001
258
US
I have a javascript that reads a recordset that has 2 images stored in it:


<script>
// Set slideShowSpeed (milliseconds)
var slideShowSpeed = 5000

// Duration of crossfade (seconds)
var crossFadeDuration = 3

// Specify the image files
var Pic = new Array() // don't touch this
// to add more images, just continue
// the pattern, adding to the array below

Pic[0] = '../uploads/<%=rs("FileName1")%>'
Pic[1] = '../uploads/<%=rs("FileName2")%>'
//Pic[2] = '3.jpg'
//Pic[3] = '4.jpg'
//Pic[4] = '5.jpg'

var t
var j = 0
var p = Pic.length

var preLoad = new Array()
for (i = 0; i < p; i++){
preLoad = new Image()
preLoad.src = Pic
}

function runSlideShow(){
if (document.all){
document.images.SlideShow.style.filter="blendTrans(duration=2)"
document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)"
document.images.SlideShow.filters.blendTrans.Apply()
}
document.images.SlideShow.src = preLoad[j].src
if (document.all){
document.images.SlideShow.filters.blendTrans.Play()
}
j = j + 1
if (j > (p-1)) j=0
t = setTimeout('runSlideShow()', slideShowSpeed)
}
</script>





This code displays the two images in a slideshow fashion:

<img src="../uploads/<%=rs("FileName1")%>" name='SlideShow' width=150 height=150>





Here's my problem. If both images exist in the fields FileName1 and FileName2, the script works fine. There will be sometimes where I'll only have FileName1 image and no image for FileName2. Is there a way for the script to see if fileName2 is empty to just use FileName1? If FileName2 is empty, I get a no image displayed when the script rotates to that image.
 

Change this:

Code:
Pic[0] = '../uploads/<%=rs("FileName1")%>'
Pic[1] = '../uploads/<%=rs("FileName2")%>'

to this:

Code:
Pic[0] = '../uploads/<%=rs("FileName1")%>';
Pic[1] = '../uploads/<%=rs("FileName2")%>';
if (Pic[1] == '../uploads/') Pic[1] = Pic[0];

Hope this helps,
Dan


 
I need this script, after it shows the second image to stop and keep showing only the second image until the user exits the page. Is this possible?
 
Yes,

Change
Code:
   if (j > (p-1)) j=0
   t = setTimeout('runSlideShow()', slideShowSpeed)

to
Code:
   if (j < p){   
      t = setTimeout('runSlideShow()', slideShowSpeed);}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top