我想要一个组合框从其他组合框中填充自己,当用户从组合框中选择一个选项时,它将填充同一页面上的组合框,其中包含与组合框中的选择相关的信息。
下面是我从下拉组合框中选择选择值时用于填充组合框的代码。但它不起作用,组合框仍然空白。
提前干杯谢谢:)
HTML
<form role="form" action="" method="post">
<div class="col-md-3">
<div class="form-group">
<label>Brand Name</label>
<select name="BRAND_CODE" id="BRAND_CODE" required="" class="form-control" onChange="getPRODUCT(this.value);">
<option value="">Choose Brand</option>
<option value="1">Brand A</option>
<option value="2">Brand B</option>
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Production Name</label>
<select name="PRODUCT_CODE" id="PRODUCT_CODE" required="" class="form-control" onChange="getPRODUCT(this.value);">
<option value="">Choose Production</option>
<option value="1">Product 1</option>
<option value="2">Product 2</option>
<option value="3">Product 3</option>
</select>
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label>Buyer</label>
<select name="BUYER_CODE" id="BUYER_CODE" required="" class="form-control">
<option value="">Choose Buyer</option>
</select>
</div>
</div>
</form>
AJAX
<script type="text/javascript">
function getPRODUCT(val) {
$.ajax({
type: "POST",
url: "check_buyer.php",
data:['BRAND_CODE='+val,'PRODUCT_CODE='+val],
success: function(data){
$("#BUYER_CODE").html(data);
}
});
}
</script>
check_buyer.php
<?php
require_once("module/conn/conn.php");
?>
<option value="">Choose Buyer</option>
<?php
if(!empty($_POST["PRODUCT_CODE"])) {
$PRODUCT_CODE = $_POST["PRODUCT_CODE"];
$BRAND_CODE = $_POST["BRAND_CODE"];
$sql ="select BUYER_CODE,BUYER_NAME from m_buyer where PRODUCT_CODE = '$PRODUCT_CODE' and BRAND_CODE = '$BRAND_CODE'";
$results = $conn->query($sql);
while ($rowz = $results->fetch_assoc()) {
?>
<option value="<?php echo $rowz["BUYER_CODE"]; ?>"><?php echo $rowz["BUYER_NAME"]; ?></option>
<?php
}
}
?>
答案 0 :(得分:0)
您的BRAND_CODE
和PRODUCT_CODE
应该引用不同的值,请尝试将功能更改为
function getPRODUCT(val) {
$.ajax({
type: "POST",
url: "check_buyer.php",
data: { 'BRAND_CODE': $("#BRAND_CODE").val(), 'PRODUCT_CODE': $("#PRODUCT_CODE").val() },
success: function(data) {
$("#BUYER_CODE").html(data);
}
});
}