I'm using jquery ui autocomplete in an asp.net web form, searching an image repository resulting in a list with imagethumb and title.
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$(".autosuggest").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "service.asmx/Search",
data: "{'searchtext':'" + document.getElementById('txtSearch').value + "'}",
dataType: "json",
success: function (data) {
response($.map(data.d, function (item) {
return {
pageno: item.PageNo,
ImageUrl: item.ImageUrl
};
}));
},
error: function (result) {
alert("Error");
}
});
},
focus: function( event, ui ) {
$("ul li a").value;
return false;
},
}).data('autocomplete')._renderItem = function (ul, item) {
return $('<li>')
.data('item.autocomplete', item)
.append("<a><img src='" + item.ImageUrl + "' />" + item.pageno + "</a>")
.appendTo(ul);
};
}
</script>
html
<div>
Search:
<input type="text" id="txtSearch" class="autosuggest" />
</div>
It's working fine, but when I select an item, it doesn't fill in the text box. Where am I going wrong? Any Help appreciated.