I have a tree structure in a SQL database; the tree has four levels, so every node in the Tree is in level 1, 2, or 3, and of course a single root node on level 0. Each database entry has the fields title, parentname, and level (0, 1, 2, or 3).
I want to create a series of a maximum of three drop-down boxes in an HTML form. In the beginning, the page should only display one drop-down box, populated only with the Tree nodes that are on Level 1. Choosing one of these should generate a second drop-down box, populated with all of the selected node's children (all Level 1 nodes have children). Then choosing one of those should do the same if a third drop-down is required (about half of Level 2 nodes have children nodes).
How would I go about doing this. Would I have to use PHP to generate all of the javascript on change events?
Try testing this exact script to make sure it works, then you can tweak it. I wasn't sure if you needed it to work backwards.. i.e. changing level 1 after level 4 has been selected.
index.php
ajax.php