title: jQuery autocomplete - How to view item label but submit item value
body: <p>I am totally new to javascript and am probably biting of more than I can chew, but I am trying to get the <a href="http://jqueryui.com/demos/autocomplete/#remote" rel="noreferrer">jQuery autcomplete</a> widget working on my Rails site.</p>
  <p>I have a page called &quot;links&quot; where I want to be able to assign a person to a link. Using the autocomplete I should be able to have a textbox that drops down a list of peoples names suggested by the autocomplete, and when selected, the persons name remains in the textbox. But when the form is submitted I don't want the persons name sent with the form, I want the persons ID sent with the form.</p>
  <p>So the question is how to have the persons name once selected, remain in the textbox, but once submitted the persons id is submitted.</p>
  <p>In Rails, this is how I am supplying the JSON data from my Person controller:</p>
  <pre><code>def index  
    if params[:term]
      @people = Person.find(:all,:conditions =&gt; ['given_name LIKE ?', &quot;#{params[:term]}%&quot;],  :limit =&gt; 5)
    else
      @people = Person.all
    end
    
    respond_to do |format|  
      format.html # index.html.erb  
      format.json { render :json =&gt; @people.to_json(:only =&gt; [:id, :given_name]) }
      end
  end
  </code></pre>
  <p>The above outputs the following JSON text:</p>
  <pre><code>[{&quot;person&quot;:{&quot;id&quot;:1,&quot;given_name&quot;:&quot;dale&quot;}},{&quot;person&quot;:{&quot;id&quot;:2,&quot;given_name&quot;:&quot;sally&quot;}},{&quot;person&quot;:{&quot;id&quot;:3,&quot;given_name&quot;:&quot;joe&quot;}}]
  </code></pre>
  <p>Using the jQuery autocomplete plugin, how do I have the 'given_name' appear in the suggested matches, leave the 'given_name' in the textbox once selected, but send the 'id' value when the form is submitted.</p>
  <p>I think I need to specify in the javascript what to label to show and what value to send. As I am just getting the hang of javascript, if you could explain how your answer works that would be appreciated. Thanks.</p>