我有一个脚本,第一个选择框工作正常,应该使第二个选择框进一步填充,尽管由于某种原因这从未发生过。
我不知道为什么它没有正确放置第二个选择框。我知道查询两个框都有效,因为第一个框有效,尽管当您选择数字时,第二个框为空
有人可以帮助我吗?
jQuery/CSS
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.country').change(function() {
var id = $(this).val();
var dataString = 'id=' + id;
$.ajax({
type: 'post',
url: 'box2.php',
data: dataString,
cache: false,
success: function(html) {
$('.city').html(html);
}
});
});
});
</script>
<style>
label {
font-weight: bold;
padding: 10px;
}
</style>
HTML
<label>Klantvraag:</label>
<select name="country" class="country">
<option selected="selected">Kies uit lijst</option>
<?php
include 'config/instellingen.php';
$query = 'SELECT DISTINCT Klantvraag FROM `DWA` WHERE `Status DWA` = \'DBAA\' AND `Kenmerk` <> \'\'';
if ($result = mysqli_query($connect, $query)) {
while ($get = mysqli_fetch_assoc($result)) {
echo '<option value="' . $get['Klantvraag'] . '">' . $get['Klantvraag'] . '</option>';
}
}
?>
</select> <br/><br/>
<label>Contract nr.:</label>
<select name="city" class="city">
<option selected="selected">Kies uit lijst</option>
</select>
PHP
<?php
if ($_POST['id']) {
$id = $_POST['id'];
include 'config/instellingen.php';
$query = 'SELECT `Contract nr.` FROM `DWA` WHERE `Klantvraag` = \'1258819\'';
if ($result = mysqli_query($connect, $query)) {
while ($get = mysqli_fetch_assoc($result)) {
echo '<option value="' . $get['Contract nr.'] . '">' . $get['Contract nr.'] . '</option>';
}
}
}
// ^ missing bracket right here
?>