Hi,
I am having a problem and I really cant understand what’s happening. I am reading an XML file, and wanting to output links in a DIV based on what i get back. Part of the link i am creating needs to have an onClick event that will call another function.
Everytime I try and use any of the variables within my onClick (even the loop counter) it always returns the last value of the variable for all the records, ie if I have 3 records in the XML file, I can list three links but all 3 links will have the 3rd records information in there onClick event. This is the loop:
[CODE]for (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.setAttribute(‘onclick’, function(){ alert(“I’m Clicked: ” + i); });
var linkText=document.createTextNode(picy);
newLink.appendChild(linkText);
document.getElementById(‘LinkList’).appendChild(newLink);
}
Its the onClick line i’m having problems with, can anyone suggest where i’m going wrong.
Cheers
Luke