Home Jquery autocomplete, get the selected value from first textbox and populate the second textbox
Reply: 1

Jquery autocomplete, get the selected value from first textbox and populate the second textbox

min2bro
1#
min2bro Published in 2017-12-07 17:29:18Z

I wanted to populate the textbox based on the selected value in the first textbox autocomplete. However not sure how to get the selected value from first textbox and query the database for the list of values to show as autocomplete values in the second text box.

My jquery code so far:

$(document).ready(function() {
    $("#autocomplete").autocomplete({
             minLength: 7, 
             delay: 1000,
        source: function(request, response) {
            $.ajax({
                url: "autocomplete",
                dataType: "json",
                async:false,
                data: {
                    term : request.term,
                    // country_id : $("#country_id").val()
                },
                success: function(data) {
                    response(data);
                }

            });
        },
    });
});

HTML:

<input type="text" name="autocomplete-person" id="autocomplete-per" class="form-control" placeholder="Enter person name" />
  <input type="text" name="autocomplete-aadress" id="autocomplete-adrs" class="form-control" placeholder="show address of seelected name" />
I.R.
2#
I.R. Reply to 2017-12-07 17:41:32Z

On the success of your ajax call, you can put a function that makes another ajax call and get the data for the second input, using the data that you have on your response.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.308949 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO