title: Autocomplete on select event should populate input text boxes
body: <p><strong>I dont see any autocomplete values</strong></p>
  
  <p>I have an Array of object <code>[{"email":"marie@gmail.com","name":"marie"},{"email":"miss@gmail.com","name":"miss"}]</code> from the server end.</p>
  
  <p>I have three input fields 1)select tag 2) input text.I want to autocomplete all the matched strings of name property in array of object in the select tag. Upon selecting the any one of the name value say for marie.The selected value should automatically fetch its email ie.,marie@gmail.com and populate into input text. </p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;script src="https://code.jquery.com/jquery-1.10.2.js"
      type="text/javascript"&gt;&lt;/script&gt;
  &lt;link
      href="https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"
      rel="Stylesheet" type="text/css" /&gt;
  &lt;script src="https://code.jquery.com/ui/1.11.4/jquery-ui.js"
      type="text/javascript"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;script type="text/javascript"&gt;
      function handleAutocomplete(request) {
          $.ajax({
              url : 'getAdvocate.jsp?q=' + request.term,
              dataType : "json",
              type : "POST",
              contentType : "application/json; charset=utf-8",
              success : function(data) {
                  // use 'term' for custom filtering etc.
                  var options = $.grep(data, function(e) {
                      return e.name.startsWith(request);
                  });
                  return options;
              },
              error : function(response) {
                  //alert(response.responseText);
              },
              failure : function(response) {
                  //alert(response.responseText);
              }
          });
  
      }
      $(function() {
          $("#name").autocomplete({
              minLength : 0,
              delay : 0,
              scroll : true,
              autofocus : true,
              source : function(request, response) {
                  var data = handleAutocomplete(request); /* get answers from somewhere.. */
              },
              focus : function(event, ui) {
                  $("#name").val(ui.item.name);
                  return false;
              },
  
              select : function(event, ui) {
                  $("#name").val(ui.item.name);
                  $("#email").val(ui.item.email);
                  return false;
              }
          }).autocomplete("instance")._renderItem = function(ul, item) {
              return $("&lt;li&gt;")
              //.append("&lt;a&gt;" + item.name + "&lt;br&gt;" + item.email + "&lt;/a&gt;")
              .append("&lt;a&gt;" + item.name + "&lt;/a&gt;").appendTo(ul);
          };
      });
  &lt;/script&gt;
  &lt;body&gt;
      &lt;input id="name" type="text" class="form-control" /&gt;
      &lt;input id="email" type="text" class="form-control" /&gt;
      &lt;input id="mobile" type="text" class="form-control" /&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>