Reputation: 14731
I have been trying to do auto complete using JQuery and JSP, but so far I couldn't get the value in hidden field successfully, I am able to get the department name though.
Could someone point out what exactly is the problem?
Code
<link rel="stylesheet" type="text/css" href="css/jquery.autocomplete.css" />
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" src="js/jquery.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#dept").autocomplete(
"myData.jsp",
{
minChars:4,
delay:30,
autoFill:false,
matchSubset:false,
matchContains:1,
selectOnly:1,
select: function(event, ui) {
$("#hid").val(result)
}
}
);
});
and in myData.jsp I have // will move the code to Servlet
Department t = new Department ();
String query = request.getParameter("q");
List<String> tenders = t.getDepartments(query);
Iterator<String> iterator = tenders.iterator();
while(iterator.hasNext()) {
String deptName= (String)iterator.next();
String depto = (String)iterator.next();
out.println(deptName);
}
Upvotes: 2
Views: 619
Reputation: 74738
Try this:
$("#dept").on('blur keyup change', function(){
$("#hid").val($(this).val());
});
Try to get the events blur keyup
and change
on the #dept
text input when it gets these events #hid
will get the value of it.
Upvotes: 1