# Auto complete onclick

**URL:** <https://www.ruby-forum.com/t/auto-complete-onclick/168793>\
**Category:** Rails\
**Created:** [May 26, 2009, 2:35am UTC](https://www.ruby-forum.com/t/auto-complete-onclick/168793 "2009-05-26T02:35:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bartolome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bcef8e/32.png) [@bartolome](https://www.ruby-forum.com/u/bartolome)\
**Post date:** [May 26, 2009, 2:35am UTC](https://www.ruby-forum.com/t/auto-complete-onclick/168793/1 "2009-05-26T02:35:40Z")

</div>

I’d like to know how I can put the id in a field when the user clicks on  
an  
autocomplete item. I have a field with autocomplete where I wanna show  
the  
name of the user but save on the database the id. My code is the  
following  
one:

\<%= text\_field\_with\_auto\_complete :user\_id, :name, {:size =\> 15}, {:url  
=\>  
users\_path, :method =\> :get, :param\_name =\> ‘search’} %\>

Thanks in advance

–  
_Rodrigo F._  
Web D.  
SCJP

---

<div class="post-metadata">

**Author:** ![bartolome](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bcef8e/32.png) [@bartolome](https://www.ruby-forum.com/u/bartolome)\
**Post date:** [May 26, 2009, 11:55pm UTC](https://www.ruby-forum.com/t/auto-complete-onclick/168793/2 "2009-05-26T23:55:54Z")

</div>

Rodrigo,

You can either use a hidden field for the ID or follow the approach  
covered by Ryan B. in the following railscast:

> **[\#102 Auto-Complete Association - RailsCasts](http://railscasts.com/episodes/102-auto-complete-association)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

Cheers, Sazima

On May 25, 9:34 pm, Rodrigo F. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
