Jquery autocomplete with Dynamic input box.?
- by Kaps Hasija
I have done so much R & D for Jquery Auto complete, I found some result but not as much i needed. I am giving you code which are currently i am using .
<input type="text" value="|a" name="completeMe" id="Subject" />// This input box will created by Dynamic using forloop
// My Jquery Code
$(function () {
$("#Subject").autocomplete({
source: '/Cataloging/Bib/GetSubject',
minLength: 1,
select: function (event, ui) {
// Do something with "ui.item.Id" or "ui.item.Name" or any of the other properties you selected to return from the action
}
});
});
// My Action Method
public ActionResult GetSubject(string term)
{
term = term.Substring(2, term.Length-2);
return Json(db.BibContents.Where(city => city.Value.StartsWith(term)).Select(city => city.Value), JsonRequestBehavior.AllowGet);
}
// My code is running with static input but while creating Dynamic I need to use live event but i don't know how can i use Live Event with this code.
NOTE: I am using static value of input "|a" after rendering on action i am removing that first two char to make proper search from database.
Thanks