PHP scope issue

Posted on 2013-01-25
Last Modified: 2013-01-25

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"].attachEvent("onDrag", function() { return false; });
			trees["treebox2"].attachEvent("onDrag", function() { return false; });

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");'#E6E6E6';
combo2.attachEvent("onChange",function(){ 'black';
return true;

Open in new window

Question by:1Cougar
LVL 142

Accepted Solution

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

Author Comment

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


Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now