Solved

PHP scope issue

Posted on 2013-01-25
2
273 Views
Last Modified: 2013-01-25
Hello,

I know I have a scope problem but I can't seem to figure it out.  I have the code below, where I call procedure "doOnLoad()" when the body loads.  In there I initialize a combo box and trees.  I have an Event handler "onChange" but it only updates my tree once.  I have an alert and it gets called twice.  Ideally I think I should just be reloading the XML when the combo box changes, but when I tried to declare the trees in doOnLoad() and then update the XML in doTree(), I got an error "Trees not defined".  I guess if I could declare the trees in doOnLoad and be able to access them and update XML in doTree, that would be the best, but I don't know how to go about this.

I hope I am making sense.  Below is my code.  Thank you!

function doTree(){
	alert("In tree!");
	
	var trees = {};

trees["treebox1"] = new dhtmlXTreeObject("treebox1","100%","100%",0);
trees["treebox2"] = new dhtmlXTreeObject("treebox2","100%","100%",0);
trees["treebox3"] = new dhtmlXTreeObject("treebox3","100%","100%",0);
			trees["treebox1"].enableDragAndDrop(true);
			trees["treebox1"].attachEvent("onDrag", function() { return false; });
			trees["treebox1"].setSkin("dhx_terrace");
			trees["treebox1"].setImagePath("../../DHTMLX/dhtmlxTree/dhtmlxTree/codebase/imgs/csh_dhx_terrace/");
			trees["treebox1"].loadXML("getTree.php?what=1&thisID=0",function(){
			//trees["treebox1"].openAllItems(0);
			});
			trees["treebox2"].enableDragAndDrop(true);
			trees["treebox2"].attachEvent("onDrag", function() { return false; });
			trees["treebox2"].setSkin("dhx_terrace");
			trees["treebox2"].setImagePath("../../DHTMLX/dhtmlxTree/dhtmlxTree/codebase/imgs/csh_dhx_terrace/");
			trees["treebox2"].loadXML("getTree.php?what=2&thisID="+document.getElementById('thisid').value,function(){
			//trees["treebox2"].openAllItems(0);
			});
			return;
	
}



function doOnLoad() {
	window.dhx_globalImgPath = "../../DHTMLX/dhtmlxCombo/codebase/imgs/";
var comboObject2 = {
    parent: "combo_zone2",
    width: 500,
    readonly: true,
    xml: "getContractXML-1.php"
}
var combo2 = new dhtmlXCombo(comboObject2);
combo2.setComboText("Please select a company");
combo2.DOMelem_input.style.color='#E6E6E6';
combo2.attachEvent("onChange",function(){ 
combo2.DOMelem_input.style.color= 'black';
document.getElementById('thisid').value=combo2.getSelectedValue();
doTree();
return true;
});
	

Open in new window

0
Comment
Question by:1Cougar
2 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38818823
Either, you declare the variable as global, or you have to pass the variable as parameter
0
 

Author Comment

by:1Cougar
ID: 38819080
Thanks, that was totally it.  I somehow wasn't seeing where to declare it but have it all sorted out now.

Cheers,
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question