I'm using the xmlHttpRequest object to gather images and place them on a page. Later in the script, I need to add a function to their onClick property so they can do the business I need them for. However, after having placed them on the page, I cannot then snatch them up again to add the onClick.
I'll readily accept the premise that I'm doing something backwards, but because a) the function I want to add to the onClick property is a method of the kioskDemo prototype and b) I want to pass the 'this' object to the method to make it work, it seems to me that I would want to add the onClick method later in the program, rather than when I'm building it in the getImages method.
Here's the relevant code:
I'll readily accept the premise that I'm doing something backwards, but because a) the function I want to add to the onClick property is a method of the kioskDemo prototype and b) I want to pass the 'this' object to the method to make it work, it seems to me that I would want to add the onClick method later in the program, rather than when I'm building it in the getImages method.
Here's the relevant code:
Code:
kioskDemo.prototype.getImages = function() {
var source = '/global/mul/digital/kiosk/xml/'+this.page+'_'+this.country+'.xml';
HTTP.getXML(source, return_result);
function return_result(result) {
var items = result.getElementsByTagName('collection')[0];
for(x = 0; x<items.childNodes.length; x++) {
if(items.childNodes[x].tagName) {
var images = items.childNodes[x];
var nameTag = images.tagName.toString();
var target = document.getElementById(nameTag);
for(y = 0; y < images.childNodes.length; y++) {
if(images.childNodes[y].tagName) {
var hlink = document.createElement('A');
hlink.setAttribute('href','javascript: void(0);');
hlink.setAttribute('class', 'k_button');
// addEvent(hlink, 'click', kioskChangeFile);
var image = document.createElement('img');
image.src = images.childNodes[y].getAttribute('src');
image.id = images.childNodes[y].getAttribute('name');
target.appendChild(hlink);
hlink.appendChild(image);
}
}
}
}
}
}
function launchKiosk() {
k.getImages();
var demo_container = document.getElementById('demo_container');
// A bunch of other unrelated code. . .
var img_buttnz = document.getElementsByTagName('A');
alert(img_buttnz.length);
/* at this point, I found out that I cannot see these objects at all. */
}
Comment