I have a dropdown which gets the information from a query using mysqli_query() now, once selecting a choice from the first dropdown I want the second dropdown to be filled with data from a difference query.
This is my code
HTML:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.17/jquery-ui.min.js"></script>
<script>
$(document).ready(function() {
$('.country').on('change', function() {
// Code to add country information in url
location.href = location.href.split('?')[0]
+ ['?country', $(this).val()].join('=');
});
});
</script>
PHP First dropdown:
<?php
$countries = mysqli_query($mysqli,"select source from nhws.masterkey group by source;");
echo "<select name='country' style=width:200px>";
echo "<option size =30 ></option>";
while($row = mysqli_fetch_array($countries)){
echo "<option value='".$row['source']."'>".$row['source']."</option>";
}
echo "</select>";
?>
PHP Second dropdown:
<?php
if (isset($_GET['country'])) {
$country = $_GET['country'];
echo $country;
$variables = mysqli_query($mysqli,"select variable from nhws.num_all_{$country} group by variable;");
echo "<select name='variable' style=width:200px>";
echo "<option size =30 ></option>";
while($row = mysqli_fetch_array($variables)) {
echo "<option value='".$row['variable']."'>".$row['variable']."</option>";
}
echo "</select>";
}
?>
Now, once a selection was choosen from the first dropdown nothing happens in the second dropdown.
Thanks!