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

i have asp.net website,
where i have a textbox with autocomplete jquery function,
now
i want to populate other textboxes based on the selection of autocomplete textbox.

jquery code:
<script type="text/javascript">
    $(document).ready(function () {
        $("#<%=txtSearch.ClientID %>").autocomplete({
            source: function (request, response) {
                $.ajax({
                    url: '<%=ResolveUrl("~/Service.asmx/GetCustomers") %>',
                    data: "{ 'prefix': '" + request.term + "'}",
                    dataType: "json",
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    success: function (data) {
                        response($.map(data.d, function (item) {
                            return {
                                label: item.split('-')[0],
                                val: item.split('-')[1]
                            }
                        }))
                    },
                    error: function (response) {
                        alert(response.responseText);
                    },
                    failure: function (response) {
                        alert(response.responseText);
                    }
                });
            },
            select: function (e, i) {
                $("#<%=hfCustomerId.ClientID %>").val(i.item.val);
            },
            minLength: 1
        });

    }); 
</script>


can anyone plz help me, how to populate other textboxes based on autocomplete textbox.

Thanks
Posted
Comments
[no name] 12-Oct-14 12:10pm    
if your text box for autocomplete is getting populated with the selected value, then based on that value, you can populate the other textboxes.
abdul subhan mohammed 13-Oct-14 3:30am    
i have a autocomplete textbox, once d user select any value, i want to populate remaining description textboxes based on autocomplete textbox, so i have tried n make the autocomplete textbox as autopoast="true", but its not calling that event to populate other textboxes. Can i populate other textboxes in jquery where i wrote for autocomplete textbox.
[no name] 13-Oct-14 3:36am    
In the select method of autocomplete does not the function for populating the other textboxes works??
abdul subhan mohammed 13-Oct-14 3:57am    
no, do u have code like that..?
[no name] 13-Oct-14 4:01am    
Please check my solution. I have given u a fiddle and a small change to your peice of code. Please check and respond back if that works.
Thanks

Please use
C#
select: function (e, i) {
                $("#<%=hfCustomerId.ClientID %>").val(i.item.value);
            },

This should work, else take a look at the fiddle below.
Fiddle for your Question[^]
Please check the above fiddle, in which I have populated two textboxes on select of autocomplete value.
One text box with the selected value
and other static string.
Hope this helps
:)
 
Share this answer
 
v2
BAsed on your comment Abdul, I found this solution. Please check if you get any help else respond back..:)
Query on code snippet to assign values from server side to array in javascript[^]
Thanks
:)
 
Share this answer
 

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