Click here to Skip to main content
15,793,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I am new to jQuery, can any one help me understand the below code to do auto complete?

                select: function(event, ui) {
                    __doPostBack($("input[id*=btn]").attr("id"), "OnClick")
                source: function(request, response) {
                    response($.map(dataArray, function(item) {
                        if (item.label.indexOf($("#autocomplete").val()) == 0) {
                            return {
                                label: item.label,
                                value: item.value
                minLength: 1

Updated 20-Sep-11 1:22am
AditSheth 20-Sep-11 7:20am    
Can you post link from where you find this.
sajithnet 20-Sep-11 7:38am


This is an event which gets called when one select an item from the drop list.

is assigning the value of the selected label the textbox.

The line
__doPostBack($("input[id*=btn]").attr("id"), "OnClick") 
is used to fire some server side event of the button with id btn.

This is the event to associate data source to the auto complete. In this case dataArray should be something like-
<script type="text/javascript"> 
 var dataArray=[{"value":"1","label":"abc"},{"value":"1","label":"abc"},{"value":"2","label":"acbc"},{"value":"3","label":"abcfd"},{"value":"4","label":"assbc"},{"value":"5","label":"aaabc"},{"value":"6","label":"ddabc"},{"value":"7","label":"dggabc"},{"value":"8","label":"dabc"},{"value":"9","label":"vvabc"},{"value":"10","label":"vabc"},{"value":"11","label":"vgafftbc"},{"value":"12","label":"vabc"},{"value":"13","label":"vddabc"}]//]]>

Each time there is any change in the text box, it call the corresponding function. This function takes response as a second parameter which is nothing but a function which accept array of label value. And in this case jQuery map[^] is used to filter the matching value.

For reference check this[^] post.
Share this answer
AditSheth 20-Sep-11 7:15am    
If id of button is btn then why they find ID attribute ?
i thing btn is not id. and what is mean by '*' in [id*=btn]
sajithnet 20-Sep-11 7:35am    
AnupDasGupta ur comment is really useful thanks a lot dear.hope i will get help further
To understand what the expression $("input[id*=btn]") means you'll have to learn about jQuery selectors. Selectors are expressions that let you identify one or many DOM elements. jQuery has a whole bunch of selectors for your convenience and here is the link where you can learn all about them:[^].

Best Regards,

Share this answer
sajithnet 20-Sep-11 8:30am    
thanks MRB

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900