title: jquery.autocomplete.js - how does autocomplete work?
body: <p>I call the autocomplete jquery with the result of a GET request. 
  The autocomplete function call looks like this:</p>
  
  <pre><code>$('#id_project_owner_externally').autocomplete('/pm/contact_autocomplete');
  </code></pre>
  
  <p>The url /pm/contact_autocomplete returns a list of tuples. The first part of the tuple is the name of the contact and the second part of the tuple is the id of the contact.</p>
  
  <p>The corresponding function (part of a django view) looks like this:</p>
  
  <pre><code>def iter_results(results):
          if results:
              for r in results:
                  yield '%s|%s\n' % (r.first_name, r.id)
  </code></pre>
  
  <p>Now I'm wondering what jquery autocomplete is doing with the first_name + id tuple. Acutally the first_name is put into the input field. But what happens with the id part. This is the important information that I need.</p>
  
  <p>Can I tell jquery that the id should be placed into a certain hidden field? </p>
  
  <p><a href="http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/" rel="nofollow noreferrer">link to js source</a></p>
  
  <p>Edit: The solution</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;&lt;!--//
          $('#id_project_manager_externally').autocomplete('/pm/contact_autocomplete').result(function(event, item) {$('#id_project_manager_externally_hidden').attr("value", item[1]);});//--&gt;&lt;/script&gt; 
  </code></pre>