我创建了2个下拉菜单,其中第二个菜单应该对第一个选择做出反应。
我已经测试了MySQL查询和工作没有任何问题。出于某种原因,似乎页面getter.php未被激活'。有什么建议吗?
炫魅
<?php
require_once('includes/db_connect.php');
echo '<select id="first-choice">
<option>Please choose here first</option>';
$sql_lev = "SELECT
id,
klantnaam
FROM adressen
ORDER BY klantnaam ASC ";
if(!$res_lev = mysqli_query($mysqli, $sql_lev)) { include('includes/error_database.php'); die; }
while($row_lev = mysqli_fetch_array($res_lev)) {
echo '<option value="'.$row_lev['id'].'">'.$row_lev['klantnaam'].'</option>';
}
echo '
</select>
<br>
<select id="second-choice">
<option>Please choose from above</option>
</select>';
?>
<script type="text/javascript">
$("#first-choice").change(function() {
$("#second-choice").load("getter.php?choice=" + $("#first-choice").val());
});
</script>
getter.php
<?php
require_once('includes/db_connect.php');
$choice = mysqli_real_escape_string($mysqli, $_GET['choice']);
echo '<option value="">Choose here now</option>';
$sql_cnt = "SELECT
id,
naam
FROM contactpersoon
WHERE klant_id = ".$choice."
ORDER BY naam ASC ";
if(!$res_cnt = mysqli_query($mysqli, $sql_cnt)) { include('includes/error_database.php'); die; }
while($row_cnt = mysqli_fetch_array($res_cnt)) {
echo '<option value="'.$row_cnt['id'].'">'.$row_cnt['naam'].'</option>';
}
?>
答案 0 :(得分:0)
用于$("#first-choice option:selected")
<script type="text/javascript">
$("#first-choice").change(function() {
$("#second-choice").load("getter.php?choice=" + $("#first-choice option:selected").val());
});
</script>