脚本有问题..我尝试了不同的解决方案而没有解决这个问题。我不擅长Javascript所以它可能在javascript我有一个问题..
我正在尝试使用与先前选择相关的选项填充辅助选择列表。我认为到目前为止我的代码非常简单。
提前致谢!
HTML page.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$("#first-choice").change(function() {
$("#second-choice").load("get.php?choice=" + $("#first-choice").val());
});
</script>
<select id="first-choice">
<option selected value="base">Please Select</option>
<option value="1">1</option>
<option value="2">2</option>
</select>
<br>
<select id="second-choice">
<option>Please choose from above</option>
</select>
PHP get.php
<?php
$host = "localhost";
$user = "user";
$password = "password";
$dbname = "dbname";
$link = mysqli_connect($host, $user, $password, $dbname);
$choice = mysqli_real_escape_string($_GET['choice']);
$results = mysqli_query($link, "SELECT * FROM subcategories WHERE parentcat='$choice'") or die(mysqli_error($link));
while ($row = mysqli_fetch_array($results)) {
echo "<option>" . $row{'subcat'} . "</option>";
}
?>