473,587 Members | 2,463 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

appendChild objects not recognized?

13 New Member
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 2025
iam_clint
1,208 Recognized Expert Top Contributor
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
holisticnetworking
13 New Member
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
5166
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 calculate the totals in each row. when i try however, i receive the error: "Error: 'elements' is null or not an object"
1
2776
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 javascript that adds a new line with HTML inputboxes and lists to the form if they press a button.
1
1728
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) img2.src="file://d:/datatools/c++/china1.jpg"
2
10844
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 it if anyone need such a function. function append_children() { var a = append_children.arguments;
2
1450
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, AppendChild, making width grow? Hi,
3
6526
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 get an invalid argument error. Here's the code.... var docBody = top.frames.document.getElementsByTagName("BODY");
15
2051
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 Stuart Langridge's book "DHTML Utopia: Modern Web Design using Javascript and DOM" which seems pretty good. It covers the basics. The next thing I'd like to do is add a Save button to this little page I came up with. I may use Sam Stephenson's...
4
8320
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 developed a simple ASP.NET application with a web page that should display a list of users. This list page is designed to start with an empty table (with columns defined), and, onload, send an XmlHttp request to a server component (a.k.a. ListServer)....
2
2241
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 no error message from IE. I'm new to these routines. Could someone shed some light on where I could be going wrong? Here's the code: <html> <head> <script type='text/javascript'> function makeTable() {
0
7924
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7854
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7978
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5395
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.