Reputation: 721
I have limited experience with Jquery in general and this is the first time I have tried using the autocomplete. I have defined the ready event as per below (please note I have used a dummy url in my example).
$(document).ready(function() {
$("#ELEMENTID").autocomplete({
source: "example.asp",
minLength: 3
});
});
If my example.asp returns a simple array: ["val1", "val2", val3"]
this works well and the textbox with id "ELEMENTID" updates accordingly. I'm actually using this as a suburb/postcode/state validator. The user will be entering a suburb, and after making their selection I would like to also auto populate the postcode and suburb fields. How can I pass these extra values back in my example.asp, and
How do I then access them through the page that is making the call?
Upvotes: 1
Views: 256
Reputation: 4320
You can prepare list of dictionaries like this:
[{"label":"some_label", "value":"val1", "postcode": "some_postcode"},
{"label":"some_label2", "value":"val2", "postcode": "some_postcode2"},
{"label":"some_label3", "value":"val3", "postcode": "some_postcode3"}]
and set the appriopriate values by using select event:
$(document).ready(function() {
$("#ELEMENTID").autocomplete({
source: "example.asp",
minLength: 3,
select: function(event, ui) {
$('#id_postcode').val(ui.item.postcode);
}
});
});
Upvotes: 1