I need to create 14 javascript Ajax objects and assign properties and events to them. Since most of the code is just being repeated, I'd like to do the whole thing in a loop using an array for the object names.
This is a portion of the code as it now stands:
boxe2_tree = new dhtmlXTreeObject("boxe2_div", "100%", "100%", 0);
boxe2_tree.enableCheckBoxes(1);
// etc.
boxe2_tree.loadXML("./xml/boxe.xml",function(){loadTree('boxe2_tree');});
warn2_tree = new dhtmlXTreeObject("warn2_div", "100%", "100%", 0);
warn2_tree.enableCheckBoxes(1);
// etc.
warn2_tree.loadXML("./xml/warn.xml",function(){loadTree('warn2_tree');});
// Continue for 12 more trees
And this is what I would like to do:
var arTrees = new Array('boxe', 'warn', 'safe', 'indi', 'desc', 'dosa', 'stud'); // etc.
for (x in arTrees){
var treeName = arSections[x] + "2_tree";
treeName = new dhtmlXTreeObject(arSections[x] + "_div", "100%", "100%", 0);
treeName.enableCheckBoxes(1);
// etc.
treeName.loadXML("./xml/" + arSections[x] + ".xml");
}
I tried using eval, but I couldn't get it to work.
I'd appreciate any help anyone can offer.