I have two drop-downs, both are scraped from directories. The first drop-down chooses the path to take i.e. scrape the first folder. The second drop-down determines the image to display from that folder. However I cannot get the value of the second drop-down to update when the first drop-down is changed. This means the drop-down is empty.
Code:
<select name="Image1">
<option value="" selected="selected"></option>
<?php
$dir1 = "../img/";
$dh1 = opendir($dir1);
while (false !== ($filename1 = readdir($dh1))) {
if ($filename1 === '.' or $filename1 === '..' or $filename1 === '.htaccess' or $filename1 === 'theme' )
continue;
else
$files1[] = $filename1;
echo "<option value='".$dir1 ."/". $filename1 . "'>" . $filename1 . "</option>"; }
sort($files1);
?>
</select>
<select name="Image2" onChange="showImage(this.value)">
<option value="" selected="selected"></option>
<?php
$dirname = $_POST['Image1'];
$dir = "../img/" . $dirname . "/";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if (strpos($filename, '.JPG')!== false)
$files[] = $filename;
else
continue;
echo "<option value='".$dir ."/". $filename . "'>" . $filename . "</option>"; }
sort($files);
?>
</select>
<div id="image_div"></div>
<script type="text/javascript">
function showImage(value)
{
var img = "<img src='"+value+"' style=width:55em; height:55em; />";
document.getElementById('image_div').innerHTML = img;
}
</script>
Edit: I have read through many other questions and not been able to implement them due to there being either SQL or predefined values, so simply filtering the select by id will not work.