jQuery UI autocomplete on select input box
I have JSON data feeding id
, label
and value
as keys for values.
When I select data I select the label
/value
values onto the textbox #id_emp_name
. I want to be able to insert the id
of the label
/value
that was selected into the hidden textbox #id_emp_id
.
My current javascript code:
$('#id_emp_name').autocomplete({
source: '/best_choose/employees.json',
min开发者_StackOverflow社区Length: 1,
dataType: 'json',
max: 12
});
Use the "select" option of autocomplete to define a function to handle selections:
$('#id_emp_name').autocomplete({
source: '/best_choose/employees.json',
minLength: 1,
dataType: 'json',
max: 12,
select: function(event, ui) {
$('#id_emp_id').val(ui.item.id);
}
});
精彩评论