View Full Version : How do you autopopulate the smart folding tree menu

01-12-2006, 04:20 PM
DD = Smart Folding Tree menu

Hello everyone and thanks for taking the time to read this posting. I happened across this "smart folding tree menu" script whilst browsing the net for such a script, it is great and so simple to use, especially for someone who has limited skills when it comes to coding, I have got the script customized to do what i want it to except for one issue. Some of the levels in the tree menu i want to autopopulate (create on the fly) from data contained in a seperate file (the data in this file changes from time to time, this is why I dont want to hard code all of the tree menu). So for instance, i open up a level on the tree and when i click on the next level down it will read the external file and auto build the rest of the tree sub levels. I am ok with perl and cgi so i don't mind using that code to get at the data and build the tree.

My problem is with the existing code, i don't know how to break out of that to get the external data.

thanks, Mark.

04-14-2006, 03:54 AM
Mark did u ever figure out how to do this? Does anyone know how to build the tree on the fly don't really need to read from a file but would like to build the tree on the fly.

Any help greatly appreciated

11-28-2006, 12:32 PM
I think you may be asking the wrong question.
Perhaps you should be asking:

"How do I auto-generate the simple unordered list, and then create the tree?"

Is that really what you want to know?

11-28-2006, 01:07 PM
Using Perl/CGI the task should be simple, because you'll have more flexibility. The key in the JavaScript is just to use document.writeln() to get the list into the script.

I tried a simple test by replacing the example menu list with the JavaScript code to create that script. It worked just fine that way. Here's the appropriate excerpt from that code:

<ul id="treemenu1" class="treeview">

<script language="Javascript">

document.writeln("<li>Item 1</li>");
document.writeln("<li>Item 2</li>");

document.writeln("<li>Folder 1");
document.writeln(" <ul>");
document.writeln(" <li>Sub Item 1.1</li>");
document.writeln(" <li>Sub Item 1.2</li>");
document.writeln(" </ul>");
document.writeln("<li>Item 3</li>");

document.writeln("<li>Folder 2");
document.writeln(" <ul>");
document.writeln(" <li>Sub Item 2.1</li>");
document.writeln(" <li>Folder 2.1");
document.writeln(" <ul>");
document.writeln(" <li>Sub Item 2.1.1</li>");
document.writeln(" <li>Sub Item 2.1.2</li>");
document.writeln(" </ul>");
document.writeln(" </li>");

document.writeln("<li>Item 4</li>");

Expanding on this, you could possibly use a JavaScript include that would contain the writeln statements to create the list. That include file could be auto-generated by a Perl script if you like.

You might also be able to use the eval() function in JavaScript to dynamically create the list, althought I haven't tried this.

Does this help?