名と姓に基づいて検索する以下のコードがあります。名の後にスペースを押すと、検索結果が消えます。スペースを押した後に検索結果を表示する方法。firstname/LastName のテキストボックスで ajax 関数を呼び出しています。
<script type="text/javascript">
function lookup(inputString) {
if(inputString.length == 0) {
$('#suggestions').hide();
} else {
$.post("states.jsp", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
}
function fill(thisValue) {
$('#inputString').val(thisValue);
setTimeout("$('#suggestions').hide();", 200);
}
</script>
// States.JSP ファイル
String sql = "SELECT EMP_EMPLOYEE_ID, EMP_FNAME, EMP_LNAME FROM UAP.dbo.UAP_EMPLOYEE where EMP_FNAME LIKE '%"+name+"%' OR EMP_LNAME LIKE '%"+name+"%';";
Statement stm = con.createStatement();
stm.executeQuery(sql);
ResultSet rs= stm.getResultSet();
while (rs.next ()){
out.println("<li onclick='fill(\""+rs.getString("EMP_FNAME")+" " +rs.getString("EMP_LNAME")+"\");'>"+rs.getString("EMP_FNAME")+" "+rs.getString("EMP_LNAME")+" </li>");
}}catch(Exception e){
out.println("Exception is ;"+e);
}