Yes, it is indeed possible.
You can simply populate your first list-box in any way you see fit and instruct it, via the 'onChange' event to submit the form. The form's action property would point to the very page it is on, causing the page to refresh and the data to be sent along for the ride.
The you can simply have you PHP code check if the first box has a value and populate your second box based on the value of the first box.
This example is quite static, but shows what I mean. You will of course have to replace the huge array of data with data from whatever source you get your data from and modify the foreach() loops accordingly.
-
<?php
-
// Get the values of the list-boxes
-
$firstBox = @$_POST['firstBox'];
-
if(empty($firstBox))
-
$firstBox = "first";
-
$secondBox = @$_POST['secondBox'];
-
if(empty($secondBox))
-
$secondBox = "first";
-
-
// Print the form header
-
echo '<form action="?" method="POST">';
-
-
// Crete the data for the boxes
-
// Note, this will most likely be
-
// replace by your date, however you get it.
-
$boxData = array(
-
"first" => array(
-
"Title" => "First",
-
"Value" => "first",
-
"Data" => array(
-
"first" => "First of the first",
-
"second" => "Second of the first",
-
"third" => "Third of the first"
-
)
-
),
-
"second" => array(
-
"Title" => "Second",
-
"Value" => "second",
-
"Data" => array(
-
"first" => "First of the second",
-
"second" => "Second of the second",
-
"third" => "Third of the second"
-
)
-
)
-
);
-
-
// Print the first box
-
echo '<select name="firstBox" onChange="submit();">';
-
foreach($boxData as $v) {
-
$selected = "";
-
if($v['Value'] == $firstBox) $selected = " selected";
-
echo ' <option value="'. $v['Value'] .'"'. $selected .'>'. $v['Title'] .'</option>';
-
}
-
echo '</select>';
-
-
// Print the second box
-
echo '<select name="secondBox" onChange="submit();">';
-
foreach($boxData[$firstBox]['Data'] as $k => $v) {
-
$selected = "";
-
if($k == $secondBox) $selected = " selected";
-
echo ' <option value="'. $k .'"'. $selected .'>'. $v .'</option>';
-
}
-
echo '</select>';
-
-
-
// Close the form
-
echo '</form>';
-
-
// Show the selected boxes
-
echo "<p>You have selected: $firstBox > $secondBox </p>";
-
?>
-