0
根据第一个下拉菜单选择填充第二个下拉菜单。我已经将它编码到了一个程度,但似乎我在某处丢失了某些部分。 在此先感谢。根据第一个下拉菜单选择加载第二个下拉菜单
HTML代码:
<div class="form-group">
<label >Category</label>
<select id="disabledSelect" class="form-control" name="product_category" onchange="ajaxfunction(this.value)">
<option active>Select a Category</option>
<?php
load_category_dropdown();
?>
</select>
</div>
<div class="form-group">
<label >Category</label>
<select id="sub" class="form-control" name="sub" >
<option active>Select a Category</option>
</select>
</div>
AJAX功能:
<script type="text/javascript">
function ajaxfunction(parent)
{
$.ajax({
url: 'process.php?parent=' + parent;
success: function(data) {
$("#sub").html(data);
}
});
}
</script>
process.php代码:
<?php
include("db_connect.php");
$x=$_GET['parent'];
$get_cat="SELECT * FROM categories WHERE parent_id = $x";
$run_cat=mysqli_query($con,$get_cat);
echo "<option value='1'>Hello</option>";
while($data=mysqli_fetch_array($run_cat))
{
echo "<option value='$data['cat_id']'>$data['cat_tittle']</option>";
}
?>
什么是您所遇到的错误? – Iceman
错误:第二个下拉菜单显示NO结果。 –
何时调用'ajaxfunction(parent)'? – Iceman