I am a complete novice to php, scripting and html. I am trying to dynamically generate a dropdown box with a list of folders and then I want to generate a list links to the files for the selected folders. I have been searching for the solution which I am sure is really obvious but I don't full understand the code structure
I have this to generate the dropdown box and populate with the folders in the "Docs\" directory
<!DOCTYPE html>
<html>
<body>
<select id="mySelect" >
<?php
$dirs = glob("Docs\*", GLOB_ONLYDIR);
foreach($dirs as $val)
{
echo '<option value="'.$val.'">'.basename($val)."</option>
";
}
?>
</select>
</body>
</html>
I also have this to generate links from a set folder
<!DOCTYPE html>
<html>
<body>
<?php
foreach (glob("Docs\PB02\*.pdf") as $pathtodocs)
{
$filename = basename($pathtodocs);
echo "<a href=\"$pathtodocs\">$filename</a>";
echo "<br>";
}
?>
</body>
</html>
What I don't understand is how to call the second set of code as a function based on the first set of code and have it display underneath the drop down box. I have tried with onchange but as I say, I must be missing something basic
thanks
You can make several step. Select first option, reload the page with a GET param then display the second list.
Or you can enter the beautiful world of JavaScript and use onchange and AJAX request to refresh the second list when the first change.