我有自动完成工作,但我如何处理修改?
当用户修改原始选择时会发生什么?I've got an auto-complete that, when a listing is chosen, other fields are filled in. If the user chooses a listing, then tries to modify it to something that is new (does not match anything in our DB), the其他字段需要清除。
另一种提问方式:我如何处理“新”列表?
我的代码如下
$(function() {
$( "#oName" ).autocomplete({
source: "include/organizerList.php",
minLength: 3,
select: function( event, ui ) {
$("input#oID").val(ui.item.oID);
$("input#oCID").val(ui.item.oCID);
$("div#organCity").text(ui.item.oCity);
$("div#organCountry").text(ui.item.oCountry);
}
});
});
组织者列表.php
// important to set header with charset
header('Content-Type: text/html; charset=utf-8');
$term = htmlspecialchars(strtolower($_GET["term"]));
$return = array();
$query = mssql_query("SELECT CID, oID, oName, oCity, oCountry FROM TradeShowDB_Organizers WHERE oName LIKE '%$term%'");
while ($row = mssql_fetch_array($query)) {
array_push($return,array( 'oCID'=>$row['CID'], 'oID'=>$row['oID'], 'label'=>$row['oName'] . ', ' . $row['oCity'], 'value'=>$row['oName'], 'oCity'=>$row['oCity'], 'oCountry'=>$row['oCountry'] ));
}
// encode it to json format
echo(json_encode($return));
我的html:
<input type="text" tabindex='20' id="oName" name="oName" size="60" maxlength="200" value="<?php echo $oName; ?>">
<div id='organCity'></div>
<div id='organCountry'></div>
<input type="hidden" id="oID" name="oID" value="<?php echo $oID; ?>">
<input type="hidden" id="oCID" name="oCID" value="<?php echo $oCID; ?>">