F? Fill you w? Select from server directory PHP jQuery AJAX

I have a file structure on my server that looks something like this:

enter image description here

My question is relatively complicated: how do I populate <select> html tags progressively from the contents of the sub-files of a server.

For example, below I have 3 <select> tags that mirror the file structure shown above. When the first select is changed, the jQuery should use AJAX and PHP find that directory on the server, and list all sub-files into the second <select>. When the second one is clicked, all the sub-files of that folder should be listed, and so on. Eventually I want to have 5 <select> tags.

enter image description here

I think this is best accomplished using jQuery, which detects a change in a select:

$("select").change(function() {
        var selected = $(this).children("option:selected").text();

sends that variable to AJAX, which asks a PHP file to return an array of the sub-files of that folder, and fill the next select with the data from that array. Where I am not so confident is the PHP.

What I have tried: looked at TreeView systems – not suitable. Tried to modify TreeView systems to work with selects – fruitless! Maybe someone can try and modify the one I’ve linked?

Thanks in advance, any help will be, as always, much appreciated!

This entry was posted in Codes & Scripts and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *


You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>