2

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',
    minLength: 1,
    dataType: 'json',
    max: 12
});
1

1 Answer 1

7

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);
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.