您正在使用自动完成选择产品.. 好的,现在您只需在通过自动完成选择产品时传递该产品的 id .. 然后您可以使用 Ajax 获取该特定 ID 的价格
这是HTML代码:
$("#partyName").autocomplete("getPartyAj.php",
{
width: 400,
matchContains: true,
mustMatch: false,
minChars: 0,
highlight: false,
selectFirst: true,
formatItem: function(data, i, n, value) {
return value.split("|")[0];
}
});
$("#partyName").result(function(event, data, formatted) {
$("#partyId").val(data[1]);
balance();
});
function balance()
{
var dataString = "partyId=" + $('#partyId').val();
$.ajax({
type: "GET",
url: "balanceAj.php",
data : dataString,
success:function(data){
$('#partyBalance').val(data);
}
});
}
PHP 代码:(getPartyAj.php)
<?php
include("include/config.inc.php");
$q = strtolower($_GET["q"]);
if (!$q) return;
$selectPartyQry = "SELECT partyId,partyName
FROM party
WHERE partyName REGEXP '$q'";
$selectPartyQryRes = mysql_query($selectPartyQry);
if(mysql_num_rows($selectPartyQryRes) > 0)
{
while($partyRow = mysql_fetch_array($selectPartyQryRes))
{
echo $partyRow['partyName'].'|'.$partyRow['partyId']."\n";
}
}
else
{
echo "";
}
?>