Hi,
This is my first attempt at trying to code using Ajax/Javascript so bear with me if i've missed something obvious.
I'm trying to build a list of links in a div element based on info in an xml file. The problem is in my loop, everytime i create a link they all link to the last record of the xml file, and not the current one.
I know i am looping though the XML ok because all the links have different names. This is the code:
f - or (var i=0; i < nodes.length; i++)
-
{
-
// Get the lastname element from our XML data document
-
var doc = xmlHttpObj.responseXML;
-
var lastName = nodes[i].nodeValue;
-
var node = doc.selectSingleNode("//Customers/Customer[Lastname='" + lastName + "']");
-
var picy = node.selectSingleNode('picture/text()').nodeValue;
-
-
-
var newLink= document.createElement('a');
-
newLink.setAttribute('href','#');
-
newLink.onclick = function () {getImage('placeHolder',picy)};
-
-
var linkText=document.createTextNode(picy);
-
newLink.appendChild(linkText);
-
document.getElementById('LinkList').appendChild(newLink);
-
}
-
Its the newLink.onclick = function () {getImage('placeHolder',picy)}; that is causing the problem, the 'picy' variable is always being passed as the last xml record.
The only thing i can think is happening is it's only writing out the last link, but i cant understand why
1 1089
Heya, beakersoft. Welcome to TSDN!
The reason you are getting this behavior is because on this line: -
newLink.onclick = function () {getImage('placeHolder',picy)};
-
You are creating a function that calls getImage(), with 'placeHolder' as the first parameter, and the variable picy as the second parameter.
Note that as the loop iterates, the value of picy changes, and so all your functions ultimately do the same thing.
Instead, you'll need to create a global object and assign elements based on the id of each link: -
pices[i] = picy;
-
newLink.id = i;
-
newLink.onclick = function() { getImage('PlaceHolder', pices[this.id]); }
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brandon |
last post by:
A newbie question for you all:
Suppose you have a webpage with two frames: a main frame, and a second
frame. You have several hyperlinks to other websites in the second
frame. What you want is...
|
by: Colleyville Alan |
last post by:
I have an application that has an Access table that stores the locations of
slides in a Powerpoint file. This used to work fine when there were about 4
files and 200 slides. The database would...
|
by: Tim |
last post by:
Access 97: I have a table with a hyperlink field that I display on a form. I can
click on the form field and the hyperlink activates correctly.
However, if I try to activate the hyperlink using VB...
|
by: Chris |
last post by:
Hi,
I am writing a webpage in C#. Visual Studio .NET.
the following code does not provide me with intellisence on the context,
session, and page.cache.
When I put the large if...then...
|
by: Richard |
last post by:
I've created a simple web project, which works great on my local machine.
Every page works correctly (hyperlinks, textboxes, validator controls, etc.).
I've tried both the X-Copy method and a setup...
|
by: Seefor |
last post by:
Hi, I want my text hyperlinks to have a dotted border underneath, so I did
this which works fine:
a,
a:link,
a:visited,
a:hover,
a:active {
color: #000;
text-decoration: none;
|
by: prinsipe |
last post by:
Hi all,
what i'm doing is showing/hiding hyperlinks depending on the hyperlink clicked. it is partially working. when i call step1, all hyperlinks are hidden. but then i call step2, single and...
|
by: silversubey |
last post by:
Hello All
I have an Excel 2003 worksheet that has a column of hyperlinks that point to a web-based program. The hyperlinks are dynamic and work fine. Is it possible to have Excel use Firefox to...
|
by: Prisoner at War |
last post by:
Okay, I'd like to create a print-friendly website, so I've been
reading up on how to create print-friendly pages (without duplicating
my site, of course, by having separate versions of each...
|
by: Rajpreet |
last post by:
Hi All,
I have a document where in there are many hyperlinks pointing to files
located in a paticular directory. My concern is, if these files are
moved from this directory to some other...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |