通过 select2 选项选择时自动填充下拉列表值未提交



我在 select2 中有一个下拉列表,用于获取客户列表。选择客户时,我将显示与该客户相关的地址和联系人。 但是当我提交这些数据时,联系人和地址的值根本没有获得这些值。

这是我的脚本

<script type="text/javascript" src="js/fetchcontactaddress.js"></script>
<div class="media-body text-right">
<h4>Customer</h4>
<span><select name="customer" class="form-control is-invalid" id="selUser" onChange="showContactAdd(this);" required>
</select></span>
</div>
<div class="row" id="output"> 
//address and contact for selected customer should display here  
</div> 

获取联系地址.js

function showContactAdd(sel) {
var cat_id = sel.options[sel.selectedIndex].value;  
$("#output").html( "" );
if (cat_id.length > 0 ) {
$.ajax({
type: "POST",
url: "FetchContactsAdd.php",
data: "cat_id="+cat_id,
cache: false,
beforeSend: function () {
$('#output').html('<img src="loader.gif" alt="" width="24" height="24">');
},
success: function(html) {    
$("#output").html( html );
}
});
}
}

获取联系人添加.php

$cat_id = ($_REQUEST["cat_id"] <> "") ? trim( addslashes($_REQUEST["cat_id"])) : "";
if ($cat_id <> "" ) {
?>
<div class="media-body text-right">
<h4>Contact</h4>
<span>  <select name="contact" class="form-control is-invalid" required>
<?php 
$Scust = "SELECT con_id, fname, lname FROM cust_contacts WHERE status = 'A' AND customer=".$cat_id."";
$Cust = DB_query($Scust);
while($Crow = DB_fetch_array($Cust)) { ?> 
<option value="<?php echo $Crow['con_id']; ?>"><?php echo $Crow['fname'].' '.$Crow['lname']; ?></option>
<?php } ?>

</select>   </span>
</div>

<div class="media-body text-right">
<h4>Address</h4>
<span>  <select name="address" class="form-control">
<?php 
$cadd = "SELECT ad_id, add_name FROM cust_address WHERE status = 'A' AND customer=".$cat_id."";
$cadd1 = DB_query($cadd);
while($carow = DB_fetch_array($cadd1)) { ?> 
<option value="<?php echo $carow['ad_id']; ?>"><?php echo $carow['add_name']; ?></option>
<?php } ?>
</select></span>
</div>

选择客户时,将填充值,但是当我点击提交时,它不会同时获取地址和联系人的ID值

这已解决!我添加了 2 个不同版本的 jquery 文件。 我已经添加了$.noConflict(true);并且它起作用了。

最新更新