0

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.

1 Answer 1

1

write selection event for autocomplete also

select: function(event, ui) {
        alert(ui.item.value);
    }
Sign up to request clarification or add additional context in comments.

1 Comment

in ui parameter you can get that.. if it answer your question kindly vote :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.