Hello all,
Just took a JavaScript class, where they didn't teach us anything about slide shows. Now I have a client and I promised them a slide show on their website. I made an external Js file, and Firefox debugger keeps on giving me this error: document[place].src is undefined.

Here's the code from the external .js, again really unfamiliar with this so I based it off example code I found:

var num=0; 
var imgName="pictures/";
var slideImg= new Array();
slideImg[0]=new imageItem(imgName+"1.jpg");
slideImg[1]=new imageItem(imgName+"2.jpg");
slideImg[2]=new imageItem(imgName+"3.jpg");
                       

function imageItem(image_location)
{
  this.image_item = new Image();
  this.image_item.src = image_location;
}

function get_ImageItemLocation(imageObj)
{
  return(imageObj.image_item.src)
}

function getNextImage()
{
  
   if(num < slideImg.length)
   {
   var new_img=get_ImageItemLocation(slideImg[num]);
   return(new_img);
   }
   else 
   {
    num=1;
   }
}

function switchImage(place)
{
  var  new_img = getNextImage();
  document[place].src=new_img;
  
  setTimeOut(switchImage(place));
}

The problem should be in the last function switchImage(). Any help at all would be appreciated guys, thanks!

document[place].src=new_img;

Maybe this is what you want.

document.getElementById(place).src=new_img;

That didn't work either, but It seem to be more of a people want to make things complicated even with their tutorials. I found a much easier way of doing it in an old text book. So I just based my code off that. It works, and it makes me realize more that people have to complicate what could be simple code for no good reason. X_X

Thanks anyway guys appreciate the help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.