473,247 Members | 2,869 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,247 software developers and data experts.

appendChild objects not recognized?

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:


Expand|Select|Wrap|Line Numbers
  1. kioskDemo.prototype.getImages = function() {
  2.     var source = '/global/mul/digital/kiosk/xml/'+this.page+'_'+this.country+'.xml';
  3.     HTTP.getXML(source, return_result);
  4.     function return_result(result) {
  5.         var items = result.getElementsByTagName('collection')[0];
  6.         for(x = 0; x<items.childNodes.length; x++) {
  7.             if(items.childNodes[x].tagName) {
  8.                 var images = items.childNodes[x];
  9.                 var nameTag = images.tagName.toString();
  10.                 var target = document.getElementById(nameTag);
  11.                 for(y = 0; y < images.childNodes.length; y++) {
  12.                     if(images.childNodes[y].tagName) { 
  13.                         var hlink = document.createElement('A');
  14.                         hlink.setAttribute('href','javascript: void(0);');
  15.                         hlink.setAttribute('class', 'k_button');
  16.                         // addEvent(hlink, 'click', kioskChangeFile);
  17.                         var image = document.createElement('img');
  18.                         image.src = images.childNodes[y].getAttribute('src');
  19.                         image.id = images.childNodes[y].getAttribute('name');
  20.                         target.appendChild(hlink); 
  21.                         hlink.appendChild(image);
  22.                     }
  23.                 }
  24.             }
  25.         }
  26.     }
  27. }
  28.  
  29.  
  30.  
  31. function launchKiosk() {
  32.     k.getImages();
  33.     var demo_container = document.getElementById('demo_container');
  34. //  A bunch of other unrelated code. . .  
  35.     var img_buttnz = document.getElementsByTagName('A');
  36.     alert(img_buttnz.length);
  37.     /* at this point, I found out that I cannot see these objects at all. */
  38. }
Oct 20 '08 #1
2 2015
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. target.appendChild(hlink);  
  2. hlink.appendChild(image); 
  3.  
You should really append image to hlink before you append hlink to target
Expand|Select|Wrap|Line Numbers
  1. hlink.appendChild(image); 
  2. target.appendChild(hlink);  
  3.  
Also give your hlink a name and id in the loop.
Oct 20 '08 #2
Also give your hlink a name and id in the loop.
iam_clint, thanks very much for the quick reply, that helped!
Oct 20 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: kie | last post by:
hello, i have a table that creates and deletes rows dynamically using createElement, appendChild, removeChild. when i have added the required amount of rows and input my data, i would like to...
1
by: Nicolas Van Lancker | last post by:
Hi folks; I have this webpage, allowing users to insert multiple records in one post into the database. Because I don't know the exact number of records they want to add, I created a little...
1
by: Shawn Modersohn | last post by:
Firstly, thanks for all the help in here. My code is: <script type="text/javascript"> var img1= new Image(200,200) img1.src="file://d:/datatools/c++/boat1.jpg" var img2 = new Image(200,200)...
2
by: samuel.adam | last post by:
Hi all, I am coding an AJAX DHTML whatever application and I was fed up with always typing a lot of appendChild() functions. I created a custom one called append_children() and wanted to share...
2
by: Stewart | last post by:
Originally posted in comp.lang.javascript: Newsgroups: comp.lang.javascript From: "Stewart" Date: 23 Aug 2005 02:50:04 -0700 Local: Tues, Aug 23 2005 10:50 am Subject: FireFox, RemoveChild,...
3
by: ezmiller | last post by:
So I have some code that gets the body element of another frame and then tries to dynamically write a table. The code fails when, after creating the table, I try to append it to the document. I...
15
by: Jake Barnes | last post by:
I'm trying to learn AJAX so tonight I sat down and came up with a little toy that I can do tests with. You can see it here: http://www.publicdomainsoftware.org/ajaxExperiment.htm I've got...
4
by: Olorin | last post by:
Hello everyone. I'm playing around with some AJAX-ish stuff and encountered some problem in the JS side of the universe. Maybe someone here can suggest an alternative that works. I have...
2
by: vsanjit | last post by:
Hi all, I've been trying to create a table dynamically upon the generation of en event using the appendChild method in Javascript. This seems to work fine in Firefox, but not in IE7. There's also...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.