I got a confusion around that.
Thanks in advance.
This depends on what you consider "dynamically". If you mean generated by the server side script then it's simple: you just print the text of the
items structure by your server side script. For that you'll have to either move the structure into the main document or rename tree_items.js to
tree_items.php/asp/whatewer to make server run your code in there. This forum has dozen of my postings on this subject as well as postings by other
You can't dynamically change the structure of the hierarchy without reloading the document once the tree is initialized.
The tree uses TREE_ITEMS variable to create the hierarchy of the tree elements. This variable must be available to the browser at the time of the tree
initialization. You can either generate it as the text by your server side script or you can create/modify this variable by the client side
Returning back to terminology: You probably consider your table "populated" from the database not hardcoded. It's true for the server side: the data is pulled from the dynamic source, but next the server side script uses that dynamic data to create the HTML code of the table. That text is sent to the client's browser over the HTTP connection and it doesn't change since. For the client side (browser) your table is hardcoded, it's no different from the table it receives from the static HTML file. So it's rather generated than populated.
Another scenario is the page that has empty table or no table in it's HTML code at the time it gets to the browser. The client side script in the browser can fill it up with the data on the fly during or after the page initialization. This time you'd have to work with the document's objects (DOM) to create table's rows and cells. This is what we consider dynamic on the client side.
From your posting it sounds like you're trying to use second option. That wouldn't be my choice because of the potential browser compatibility issues and the limitation mentioned above. 'TREE_ITEMS is undefined' means that your coded didn't succeed creating TREE_ITEMS variable by the time tree attempts to use it.
My sample code looks like this:
var treeString = "var TREE_ITEMS = [ ['Select a Portfolio/Office', null,";
var idArray = new Array;
var nameArray = new Array;
idArray = "1";
idArray = "1.0070";
idArray = "1.0070.1000";
idArray = "1.0070.1000.3000";
idArray = "1.0070.1000.3000.200";
nameArray = "Priority MX";
nameArray = "Priority Payment Systems";
nameArray = "Agent Offices";
nameArray = "Cathy";
nameArray = "Victor Long";
for(i = 0; i < idArray.length; i++)
var IsLeaf = true;
for(j = i + 1; j < idArray.length - i; j++)
if(idArray == idArray[j].toString().substring(0,idArray.toString().length))
IsLeaf = false;
treeString += "],";
treeString += ",";
treeString += "]];"; //closing the root node and the tree itself respectively
As you can see from the code, my custom variable treeString is building the tree_items variable from the arrays I have. Now what I want is, as soon as I finish building this treeString variable, I want to write its content into the tree_items.js file so that I will get the right tree_items variable in the file. How can I overwrite the content of this javascritpt file by the content of my custom variable.
hey, new posting on this topic: http://www.softcomplex.com/forum/viewthread_3551/