我更新了JSON和jQuery。我需要做一个jQuery自动完成,为此我说:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
jQuery(document).ready(function($){
$('#executives').autocomplete({source:'search_executives.php', minLength:2});
});
</script>在HTML中:
<div class="rows">
<div class="labels">Search</div>
<div class="textboxs" style=" width: 175px;"><input id="executives" name="executive" /></div>
</div>我的search_executives.php是:
<?php
session_start();
if(empty($_SESSION['userid'])){
header('Location:index.php');
exit();
}
include_once('include/config.php');
$qry = "SELECT employee_id,fname,mname,lname FROM personal_details WHERE deg_id = '1'";
$res = $dbo->executeQuery( $qry ) ;
//$results[] = array('label' => $row['name']);
for( $i = 0; $i < count( $res ); $i++ )
{
$result[] = array( 'label' => $res[$i]['fname'].' '.$res[$i]['mname'].' '.$res[$i]['lname'] , 'value' => $res[$i]['employee_id'] ) ;
}
echo json_encode($result);
?>现在我的问题是-
value (例如3)。我需要打印这些高管的名字,并以他的employee_id作为他的价值。注:第一部分解决了。我忘了在LIKE中添加SQL条件!
发布于 2013-06-28 07:47:26
您必须将输入的值设置为label,然后有另一个字段在选定项时存储employee_id:
select: function(e, ui) {
e.preventDefault();
this.value = ui.item.label;
$('#other_field').val(ui.item.value);
}下面是一个例子
发布于 2013-06-28 07:25:09
您正在使用输入文本框.
文本框的value属性出现在前端文本框中,您不能更改它。在你的情况下是employee_id。
https://stackoverflow.com/questions/17359069
复制相似问题