J
jimmygoogle
OK I want to create a menu from an XML file. I am parsing it with JS.
Now it seems to be working fine until it comes time to build the menu.
I am building arrays in JS and the arrays are inside a function. How
can I make these arrays been seen by other functions? Or cant I?
here is an abridged snippet:
var xmlDoc;
if (document.implementation &&
document.implementation.createDocument){
alert ("MOZ");
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = readXML;
}
else if (window.ActiveXObject){
alert ("IE");
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) readXML()
};
}
else{
alert('Your browser cannot handle this script');
//return;
}
xmlDoc.load("http://brewdente.homedns.org/yellowstone/js/menu.xml");
function readXML(){
.....
eval(parentmenu + '= new Array(' + '"' + labelTxt + '"' + ',' +
'"' + linkTxt + '"' + ',"",' + childrenTxt + ',' + heightTxt + ',' +
widthTxt + ');');
//will look like this
//Menu1=new Array("something","http://","",0,20,225);
} //end readXML
then the rest of the functions are down below. I 'alert' all values
and everything is ok and I even am able to access different elements of
my array inside this function. How can get to these arrays outside of
this function? My code then says 'Menu1' not defined and I believe
scope is the problem. Any ideas?
Now it seems to be working fine until it comes time to build the menu.
I am building arrays in JS and the arrays are inside a function. How
can I make these arrays been seen by other functions? Or cant I?
here is an abridged snippet:
var xmlDoc;
if (document.implementation &&
document.implementation.createDocument){
alert ("MOZ");
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.onload = readXML;
}
else if (window.ActiveXObject){
alert ("IE");
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.onreadystatechange = function () {
if (xmlDoc.readyState == 4) readXML()
};
}
else{
alert('Your browser cannot handle this script');
//return;
}
xmlDoc.load("http://brewdente.homedns.org/yellowstone/js/menu.xml");
function readXML(){
.....
eval(parentmenu + '= new Array(' + '"' + labelTxt + '"' + ',' +
'"' + linkTxt + '"' + ',"",' + childrenTxt + ',' + heightTxt + ',' +
widthTxt + ');');
//will look like this
//Menu1=new Array("something","http://","",0,20,225);
} //end readXML
then the rest of the functions are down below. I 'alert' all values
and everything is ok and I even am able to access different elements of
my array inside this function. How can get to these arrays outside of
this function? My code then says 'Menu1' not defined and I believe
scope is the problem. Any ideas?