Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7915567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:29:51+00:00 2026-06-03T14:29:51+00:00

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

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:29:53+00:00Added an answer on June 3, 2026 at 2:29 pm

    populate the select option values with folder dirs:

    <div class="selects">
        <select name="folder1">
            <option value="folder1">folder1</option>
            <option value="folder2">folder2</option>
            <option value="folder3">folder3</option>
        </select>
    </div>
    

    jQuery:

    // Use live. Because the other selects will be filled with jquery.
    $("select").live("change", function() {
        var folder = $(this).val();
        var select_id = $(this).attr("name").replace('folder', '');
    
        $.ajax({
            url: 'ajax.php',
            type: "POST",
            data: {"folder": folder},
            success: function(data) {
                var select = $("<select>");
    
                select_id++;
    
                select.attr("name", "folder"+select_id).append(data);
                $(".selects").append(select);
            }
        });
    });
    

    Php:

    <?php
        $shared = "some/path/to/shared/folders/";
        $folder = $_POST['folder'];
    
        $scan = scandir($shared.$folder);
    
        $bad = array(".", "..", ".DS_Store", "_notes", "Thumbs.db");
    
        $scan = array_diff($scan, $bad);
    
        foreach ($scan as $val)
        {
            if (is_dir($shared.$folder.'/'.$val))
                echo '<option value="'.$folder.'/'.$val.'">'.$val.'</option>';
        }
    ?>
    

    I did not tested it there could be some spelling mistakes but this should do the trick

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file with structure like this: [05:58:10 08.12.1990] 125.441 [05:58:21 08.12.1990] -2.4158
I have an XML file format that contains a structure of questions: <question id=q101>
I have an xml file that contains a structure.. In this structure, I have
I have this file structure: folderIWantStuffIn/ - old_stuff Now I want to add some
I have a file with the structure like so: http://gamedev.pastebin.com/8iESYTVY but it's much bigger
I have a file from bank that is structure in very special way. Where
I've never seen anything like this. File structure: somefolder/base.php includes/stuff.php includes/constants.php base.php: <?php require(../includes/stuff.php);
Say I have the following file structure: app/ app.py controllers/ __init__.py project.py plugin.py If
Let's assume I have the following file structure: data.py foo = [] bar =
For example I have a file name call A.java. Here its structure: public class

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.