Passing arguments not working

I am trying to pass a a couple of arguments through a function. It is working fine when I pass the id of the slideshow div but any other argument is not recognized. I am more specifically trying to create a slideshow function for a webpage that can be used multiple times on the same page. I pass the id of the slideshow that I want to target and that part seems to work, but I also want to be able to setup individual speed (fadetime), number of images to cycle through (lastimage) and location of the images (imagePath).

In the example below the id parameter is working, but the imagePath is not. I also tried passing fadeTime and lastImage as arguments and neither of them are working as well.

  var fadeTime = 200;
  var lastImage = 62;
  var index = 1;
  function slideShow(id, imagePath) {
     //if (typeof(imagePath) === "undefined") imagePath = 'images';
     $(id + ' .slideShowFront').fadeTo('medium',0);
     index = (index == lastImage) ? 1 : index + 1;
     $(".slideShowBack").attr("src", imagePath + "/" + index + ".png")
     setTimeout('slideShow()', fadeTime);
            <div id="number1">
               <img class="slideShowBack"  src="images/1.png" />
               <img class="slideShowFront" src="images/2.png" />

It would be a security vulnerability if the client could request local file system files and then use JavaScript to figure out what’s in them
Browsers aren’t allowed to access the local file system unless you’re accessing a local html page. You have to upload the image somewhere. If it’s in the same directory as the html file, then you can use

function slideShow(id, imagePath) {
  console.log(id, imagePath)


This will work just fine as you have it.

I imagine it’s the setTimeout that is tripping you up. Though, I don’t know what you want this function be recursive…

setTimeout('slideShow()', fadeTime);

This needs to be

setTimeout(function() {
  slideShow(id, imagePath)
}, fadeTime);

Thank you Mark that solved the problem.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.