我有一個腳本,第一個選擇框可以正常工作,並且應該使第二個選擇框進一步填充,儘管由於某種原因永遠不會發生。鏈接的PHP/JQUERY Selectbox鏈接
我不知道爲什麼它沒有把第二個選擇框的權利。我知道查詢兩個盒子工作,因爲第一個盒子工作,雖然當你選擇數字第二個盒子是空的
有人可以幫助我嗎?
的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
?>
你最近的'if'子句缺少一個括號'}',我在末尾添加了一個括號。這可能是問題嗎? – silkfire
謝謝絲綢般的魅力! – Tredged