0

I am working on an autocomplete function for a text box and need too fetch ten results at one time and with an option which say get more hyperlink. Currently it fetches all the results.

My code so far is attached below. can you please provide guidance?

$(document).ready(function(){
            $('#<%=txtEmployeeName.ClientID%>').autocomplete({
                source: function (request, response) {
                    $("#loading").show();
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "AccountDisclosureSearch.aspx/SearchEmpByText",
                        data: "{ 'empName':'" + request.term + "'}",
                        dataType: "json",
                        success: function (data) {
                            response($.map(data.d, function (item) {
                                return {
                                    label: item.split(";")[0],
                                    val: item.split(";")[1]
                                //    name: item.split("|")[0]
                                }
                            }))
                            $("#loading").hide();
                        },

                        error: function (response) {
                            alert(response.responseText);
                            $("#loading").hide();
                        }
                    });
                },
                select: function (e, i) {

                 //   $("#<%=hempid.ClientID %>").val(i.item.val);
                    storeEmployee(i.item.label, 0, i.item.val);

                },

                 open: function(){
                $('.ui-autocomplete').css('width', '220px');
                },
                minLength: 3

            });
        });
2
  • In your backend query you can set limit like LIMIT 0,10 Commented May 19, 2017 at 5:05
  • @stackoverflkowfan Do you have access to the AccountDisclosureSearch.aspx probably yes, you can add an extra item in the JSON response so automatically the required element would be added.. Commented May 19, 2017 at 5:07

1 Answer 1

0

you can use maxResults or maxShowItems like below:

$(document).ready(function(){
            $('#<%=txtEmployeeName.ClientID%>').autocomplete({
             maxResults:10,
             or
             maxShowItems:10,
             or 
             maxHeight: 150,
             source: function (request, response) {
             //whatever you have
             }
            });
});

For more information check Here

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks Lalit but I also need a hypoerlink at the bottom to show the remaining or next 10 ...am struggling with that
is that necessary for you to use hyperlink?otherwise you could use maxHeight with scrollbar
I can try the maxheight however the hyperlink is the orig requirement :)
This is the remember to accept the answer by click the tick mark which you forgot. @stackoverflkowfan

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.