使用jquery传递值到隐藏字段的AutoComplete

时间:2013-03-25 08:04:56

标签: java javascript jquery jsp

我在JSF中有一个autoComplete输入字段。

我的JSP代码

<h:form id="setupValue">
  <input type="text" id="department" name="department"/>

<script>
    $("#department").autocomplete("getdept.jsp",{minChars: 4});
</script>
        </h:form> 

和getdept.jsp

DepartmentMB dept = new DepartmentMB ();
String query = request.getParameter("q");
List<String> dep = dept.getData(query);

Iterator<String> iterator = dep .iterator();
while(iterator.hasNext()) {
    String department = (String)iterator.next();
    String deptName=(String)it.next();
    out.println(deptName);

}

如何将department发送到隐藏字段并将deptName显示到inputText字段?

由于

1 个答案:

答案 0 :(得分:1)

你试过这样的吗?

$("#department").autocomplete({
    source: "getdept.jsp",
    minLength: 4,
    select: function(event, result) { 
        $("#hiddenfield").val(result)
    }
});

显然,获得价值的是$("#hiddenfield").val()