I'm trying to do dynamic dropdowns in PHP using a multidimensional array.
My first select box populates correctly, but upon the choice of a Building, I need the 2nd select box to show the corresponding displays (lobby, break room, etc.) for the first choice
Here's the array:
$displays = array(
"Company" => array(
"Building 1"=>array(
"Displays"=>array(
"Lobby",
"Break Room",
"Office",
),
),
"Building 2"=>array(
"Displays"=>array(
"Break Room",
"Office",
),
),
"Building 3"=>array(
"Displays"=>array(
"Lobby",
"Break Room",
),
),
"Building 4"=>array(
"Displays"=>array(
"Lobby",
"Break Room",
"Office"
),
),
),
);
And my two select boxes as of now:
/*This select option works to fill the list with building 1 through building 4, as it should*/
<select class="form-control" id="plantSelect">
<?php foreach($displays["Company"] as $area_name => $area_details): ;?>
<option><?php echo $area_name ?></option>
<?php endforeach ?>
</select>
/*I need this one to show the displays (lobby, break room, office, etc.) for each builing as it's selected*/
<select class="form-control" id="areaSelect">
<?php foreach($displays["Company"] as $area_name => $area_details): ;?>
<option><?php echo $area_details?></option>
<?php endforeach ?>
</select>
And my incomplete jquery:
<script type="text/javascript">
$("#plantSelect").change(function() {
$("#areaSelect").load("/*don't know what to put here*/" + $("#plantSelect").val());
});
</script>
Any help to finish this up is much appreciated
/*don't know what to put here*/- at this point, perhaps some research and attempts are in order? With your rep, you know we are here to help you, but to help fix your issues, not to write it for you/*don't know what to put here*/, which are vital, you've received an answer which worked for you, glad you have, but we need to see what you've got, even if someone writes up something different. We are here to help fix what's broken - instead, you've had the code written for you