Pasrsing JSON data for autocomplete

Pasrsing JSON data for autocomplete

Hi,

Referring to the below code, i want to autocomplete on text box with id name with data as the source.
For the autocomplete Label should be displayName and value should be uid.After selecting one of the value corresponfing email id should be populated in the emailid text field.

I am not able to achieve this.Please help
  1. <input type="text" id="name">
  2. <input type="text" id="emailid">
  3. var data={"users":[
  4.              {"uid":"123","displayName":"User 123","mail":"123@example.com"},
  5.              {"uid":"456","displayName":"User 456","mail":"456@example.com"},
  6.              {"uid":"789","displayName":"User 789","mail":"789@example.com"},
  7.          ]};
  8. $("#name").autocomplete({
  9.         source: data,
  10.         width: 300,
  11.         max: 20,
  12.         delay: 100,
  13.         minLength: 1,
  14.         autoFocus: true,
  15.         cacheLength: 1,
  16.         scroll: true,
  17.         highlight: false,
  18.         select: function(event, ui) {
  19.         //var selectedObj = ui.item; 
  20.        
  21.         }
  22.     });