UI AUTOCOMPLETE - Selection Populates Additional Fields
by bizamajig
HTML
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.12/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.12/themes/black-tie/jquery-ui.css">
<input id="autocomplete" type="text" />
<input id="name" type="text" />
<input id="code" type="text" />
JavaScript
var source =
[
{
"value": "John's wild bacon emporium",
"code": "BACON"
},
{
"value": "Jill and Jack's well",
"code": "WELL"
},
{
"value": "Herp and derp",
"code": "HD"
}
];
$("#autocomplete").autocomplete({
source: source,
select: function(event, ui) {
$("#name").val(ui.item.value);
$("#code").val(ui.item.code);
}
});