The variable x is undefined. From what you're saying though, I would tend to think it's an xml document. However, the code shows no attempt at retrieving that document and making it available to be parsed by the code. If it were, there would have to be enough of "tag-name" in it to cover all i, and these would start ay 0 not 1. So something like:
Code:
function list(){
var html='', answer;
for(var i = 0; i < 9; ++i){
answer = x.getElementsByTagName('tag-name')[i].firstChild.nodeValue;
// x is assumed to be an xml doc, answer will be the text value of an element from it
// assuming that element has a first child (hopefully an only child) which is a plain text node
html += '<div class="pi" onclick="list.calculate(' + answer + ')">' + i + '<\/div>\n';
}
document.write(html);
list.calculate = function(answer){
document.write(answer); // this will (if the assumptions above are correct) work, but it will overwrite he page
};
}
list();
I would use jQuery for this - especially for retrieving the xml doc and making it available for parsing. But there is generic javascript code that does the same thing, it's just more convoluted than I would ordinarily choose to write out. If you show me the xml doc, I will write up code that could be used. If you have non-jQuery code that you want to use for retrieving the the xml doc and making it available for parsing, show me that too. If it's servicable, I can use that instead of jQuery.
Bookmarks