オートコンプリートに関する多くの質問と回答を見てきましたが、私がしていることに固有のものはありません。私がやろうとしているのは、ユーザーに選択メニュー (つまり、SSN、名、姓、生年月日) からオプションを選択させることです。これはもちろんデータベースにヒットし、それぞれのデータをいっぱいにします。ユーザーがテキスト ボックスに文字を入力し始めると、オートコンプリートは適切なデータを表示して作業を開始します。問題なく動作するオートコンプリートがありますが、問題は -
選択した選択メニューの値に基づいて、アクセスするデータを決定するにはどうすればよいですか?
HTML
<div id="search-title"> Employees</div>
        <div id="search-container-large">
                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td>
                      <label for="search-text" class="search-label">Search By:</label>
                        <select name="searchkey" size="1" id="searchkey" class="dropDown">
                            <option value="0" selected> </option>
                            <option value="2" >SSN</option>
                            <option value="4" >Last Name</option>
                            <option value="3" >First Name</option>
                            <option value="5" >ID</option>
                            <option value="6" >Number</option>
                        </select>
    <input name="searchvalue" type="text" class="form-field-search" id="searchvalue"/><a href="#"><img src="img/search-btn.png" width="28" height="24" border="0" class="search-btn"/></a>
                     </td>
                   </tr>
                 </table>
    </div>
ジャバスクリプト
jQuery(function() {
    $("#searchvalue").autocomplete("http://localhost/test/getData.jsp", {
        extraParams: {
            filter: getDropdownValue()
        }
    });
});
    function getDropdownValue() {
    var compId=document.getElementById("searchkey").value;
    return compId;
    } 
JSP
<%
    DummyDB db = new DummyDB();
    String name=request.getParameter("filter");
    String query = request.getParameter("q");
    List<String> fnames = db.getData(query);
    Iterator<String> iterator = fnames.iterator();
    while(iterator.hasNext()) {
        String searchvalue = (String)iterator.next();
        out.println(searchvalue);
    }
%>
ジャバファイル
public class DummyDB {
    private int firstNames;
    private String data = "Alan, Albert, Alex, Bain, Brian, Carl, Chris, David, Derek, Frank, Frodo, Gary, Greg, Yaser";
    private List<String> fnames;
    public DummyDB() {
        fnames = new ArrayList<String>();
        StringTokenizer st = new StringTokenizer(data, ",");
        while(st.hasMoreTokens()) {
            fnames.add(st.nextToken().trim());
        }
        firstNames = fnames.size();
    }
    public List<String> getData(String query) {
        String searchvalue = null;
        query = query.toLowerCase();
        List<String> matched = new ArrayList<String>();
        for(int i=0; i<firstNames; i++) {
            searchvalue = fnames.get(i).toLowerCase();
            if(searchvalue.startsWith(query)) {
                matched.add(fnames.get(i));
            }
        }
        return matched;
    }
}