S
SM
Hello,
I have two functions: show_thumbnail() and show_photo(). See code
below.
In show_thumbnail() i create a <ul> list using Javascript and the DOM.
In the tag <a> i create a onclick function and im passing two
parameters to the show_photo() function, the path of the image and the
description
In show_photo(), the parameters are always the last image and
description of the array.
How come?
Thanks
Marco
function show_thumbnail(thumbnail)
{
...
var path, description;
var li, a, img;
var ul = document.createElement('ul');
ul.className = 'photoThumbnail';
for(var i=0; i<thumbnail.length; i++)
{
path = thumbnail.path;
description = thumbnail.description;
li = document.createElement('li');
a = document.createElement('a');
a.onclick = function() { show_photo(path, description); } ??????
img = document.createElement('img');
img.setAttribute('src', path);
a.appendChild(img);
li.appendChild(a);
ul.appendChild(li);
}
}
function show_photo(path, description)
{
alert(path); ???always showa the last path of the array
}
I have two functions: show_thumbnail() and show_photo(). See code
below.
In show_thumbnail() i create a <ul> list using Javascript and the DOM.
In the tag <a> i create a onclick function and im passing two
parameters to the show_photo() function, the path of the image and the
description
In show_photo(), the parameters are always the last image and
description of the array.
How come?
Thanks
Marco
function show_thumbnail(thumbnail)
{
...
var path, description;
var li, a, img;
var ul = document.createElement('ul');
ul.className = 'photoThumbnail';
for(var i=0; i<thumbnail.length; i++)
{
path = thumbnail.path;
description = thumbnail.description;
li = document.createElement('li');
a = document.createElement('a');
a.onclick = function() { show_photo(path, description); } ??????
img = document.createElement('img');
img.setAttribute('src', path);
a.appendChild(img);
li.appendChild(a);
ul.appendChild(li);
}
}
function show_photo(path, description)
{
alert(path); ???always showa the last path of the array
}