Hi Joe, Using the afterUpdateElement patch for the Javascript Macro Helper, I do this using the following code:
function auto_complete_on_select(element, selectedElement) { document.getElementById('encounter_client_id').value = selectedElement.childNodes.item(0).innerHTML; } Which gets called by: <%= auto_complete_field 'client', :url => {:controller => 'clients', :action => 'auto_complete_for_client'}, :after_update_element => 'auto_complete_on_select', :select => 'name' %> And my LI looks like this: <li><span class="informal">#{client.id}</span><span class="select">#{client.name}</span></li> In this case I use the new select class method and older informal style for BC purposes. Cheers, Bob Silva http://www.railtie.net/ ________________________________________ From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Nicolas Sent: Thursday, February 16, 2006 11:31 AM To: rails-spinoffs@lists.rubyonrails.org Subject: Re: [Rails-spinoffs] Autocompleter question Hi, You can play with <span class="informal"> which will be displayed, but not selected and <span style="display:none"> which won't be displayed, but selected. You can do pretty much everything with that, so you won't need to moidfy autocompleter code. Reagrds, Nico On 2/16/06, Joseph Potenza <[EMAIL PROTECTED]> wrote: Hey all, When using the Ajax.autocompleter, how would I configure it so that the user is searching based on an entry's name, but once they select an entry, I record the ID? I have the user entering a person's name in a text box to make it easier to find contacts in a large database. I know that I can display content that doesn't end up in the textbox by using the "informal" class, but how can I associate the contact's ID with the LI item and have that value be recorded into a hidden field when selected? Is there an easier way than just putting a hidden, non-standard "contactId" attribute on my LI tags and then using the afterUpdateElement option? Thanks in advance, Joe _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs