0

Luckily this forum exist, so of I go with posting a tricky question to the great masters... I am working on a program that loads multiple images in a page. The program does what it suppose to do, the problem is that I am getting an undefined error, and I don't have any idea what is the cause, the program is the following:

var imagesList = [['aaa','sss'], ['bbb','ttt']];
putImages(imagesList);
function putImages(imagesList){
  var i = 0;
  if ($(imagesList).length > 0){ 
    LoadImage(i, imagesList);
  }
}

function LoadImage(i, imagesList){
  var ele = imagesList[i][0],
    name = imagesList[i][1];    
  if(i < $(imagesList).length){
    var curr = $('<li id="pic-'+ i +'"><div>'
                         + name +'</div>').addClass("loading");
    $(curr).appendTo(".photos");
    var image = new Image();
    $(image).load(function(){       
        $(this).appendTo("#pic-" + i);  
        $(curr).removeClass("loading"); 
        LoadImage(i+1, imagesList );
    }).error(function(){
    }).attr("src", ele);
  }
}

I tried to use the advice from this link JavaScript Multidimensional Arrays, but it is just what ever I try i keep getting this error in Firefox, the other browsers seem to be ok.

Thanks a lot in advance.

Community
  • 1
  • 1
Kari
  • 1
  • 1
  • What is `imagesList`? Why are you passing it to jQuery? I'm pretty sure Firebug tells you in which line you get the error. Without knowing the structure of the array, we cannot help you. – Felix Kling May 02 '11 at 10:14
  • Ow finally I was able to edit my question, the structure of imageList can be seen at the top of the program, thanks very much! – Kari May 02 '11 at 10:25

1 Answers1

0

I'm not sure what the exact problem is, but it could be related to the fact that you pass the array to jQuery. There is not need for that.

Instead of $(imagesList).length, write imagesList.length.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • I tried that one, it didn't work. The good thing is that the program is still doing what it has to do, but I still get the undefined error. Thanks! – Kari May 02 '11 at 10:42
  • @Kari: Mmh. It seems the best way to find out the problem is to either install Firebug and go through the code step by step having a look at the values of the variables. – Felix Kling May 02 '11 at 10:56
  • I have firebug, thanks very much for your recommendation anyways :) – Kari May 02 '11 at 10:57