ollie_mo
07-02-2011, 08:47 PM
I am trying to create a page that uses javascript to call data from an xml file to present a large quantity of information through an for loop. I have gotten the id of the element to work appropriately, but using the funtion defines it as the last cycled variable definition. Is there a way to pass the value of the variable to the function definition, ie.. onclick="function(var)", so that it stays that value when the loop cycles back through?
<script type="text/javascript">
xmlhttp.open("GET","companyInfo.xml",false);
xmlhttp.send();
var xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("entry");
var idVar;
for (var i=0;i<x.length;i++)
{
idVar=x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
document.write("<button class='headerBar' onclick='showInfo(idVar)'><strong>");
document.write(x[i].getElementsByTagName("heading")[0].childNodes[0].nodeValue);
document.write("<strong></button>");
document.write("<span id='x' onclick='hideInfo(this.id)' style='display:inline;'>");
document.getElementById("x").id=idVar;
document.write(x[i].getElementsByTagName("page1")[0].childNodes[0].nodeValue);
document.write("</span>");
}
</script>
Thanks in advance to anyone that can help with this.
<script type="text/javascript">
xmlhttp.open("GET","companyInfo.xml",false);
xmlhttp.send();
var xmlDoc=xmlhttp.responseXML;
var x=xmlDoc.getElementsByTagName("entry");
var idVar;
for (var i=0;i<x.length;i++)
{
idVar=x[i].getElementsByTagName("id")[0].childNodes[0].nodeValue;
document.write("<button class='headerBar' onclick='showInfo(idVar)'><strong>");
document.write(x[i].getElementsByTagName("heading")[0].childNodes[0].nodeValue);
document.write("<strong></button>");
document.write("<span id='x' onclick='hideInfo(this.id)' style='display:inline;'>");
document.getElementById("x").id=idVar;
document.write(x[i].getElementsByTagName("page1")[0].childNodes[0].nodeValue);
document.write("</span>");
}
</script>
Thanks in advance to anyone that can help with this.