Getting the ID from a jQuery Autocomplete UI Box into a form on a JSP
I'm using JSP an开发者_StackOverflow中文版d jQuery Autocomplete UI.
I'm trying to pass the 'value' of the selected element in my autocomplete box into a form as a hidden value on my JSP.
Here is my script:
<script>
$(function() {
$("#search").autocomplete({
source: "list.jsp",
dataType: "json",
select: function (event, ui) {
$("#userId").val(ui.item.value);
return false;
}
});
});
</script>
Here is my form:
<form method="GET" action="view">
<div class="autocomplete">
<p>Search: <input id="search"></p>
</div>
<input type="hidden" name="userId" value="<%request.getParameter("userId");%>"/>
</form>
The autocomplete box works great but I can't seem to get a handle on the select element id!
Any help would be greatly appreciated... thanks in advance!
Use the following code to set the value of the hidden variable
// use <%= %>
<input type="hidden" name="userId" value="<%=request.getParameter("userId")%>"/>
You have used a scriptlet directly. Probably that is what is causing the problem.
Ok, I have solved the issue now.
I should have been using #userId as follows...
<input type="hidden" name="userId" id="userId" />
Where id="userId" references the #userId.
精彩评论