0

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!

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by soapyillusion
0

document[place].src=new_img;

Maybe this is what you want.

document.getElementById(place).src=new_img;

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.