# Autocomplete fill in text fields

**URL:** <https://www.ruby-forum.com/t/autocomplete-fill-in-text-fields/169082>\
**Category:** Rails\
**Created:** [May 29, 2009, 6:37am UTC](https://www.ruby-forum.com/t/autocomplete-fill-in-text-fields/169082 "2009-05-29T06:37:43Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 29, 2009, 6:37am UTC](https://www.ruby-forum.com/t/autocomplete-fill-in-text-fields/169082/1 "2009-05-29T06:37:43Z")

</div>

If you have an autocomplete and you have several text fields that have  
the other columns from the db.

How do you autocomplete on a box and when you select it it fills in  
the other text fields with the rest of the data from the table?

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 29, 2009, 6:30pm UTC](https://www.ruby-forum.com/t/autocomplete-fill-in-text-fields/169082/2 "2009-05-29T18:30:19Z")

</div>

When the autocomplete value is selected do an ajax call to your  
application returning the data you need to fill in using a format you  
can parse in JavaScript like JSON and set the form values.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [May 29, 2009, 6:52pm UTC](https://www.ruby-forum.com/t/autocomplete-fill-in-text-fields/169082/3 "2009-05-29T18:52:35Z")

</div>

ok where do I do that at?

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 1, 2009, 4:56am UTC](https://www.ruby-forum.com/t/autocomplete-fill-in-text-fields/169082/4 "2009-06-01T04:56:22Z")

</div>

Chris H. wrote:

> ok where do I do that at?

Have you tried googling for instructions?

When I try:

[http://www.google.com/search?q=rails+autocomplete](http://www.google.com/search?q=rails+autocomplete)

The first hit is:

> **[Auto-Complete Text Fields in Rails 2](http://codeintensity.blogspot.com/2008/02/auto-complete-text-fields-in-rails-2.html)**
>
> \[Note: this entry updated to include required routing, as I failed to mention that the first time.\] In Rails 2, the PrototypeHelper and Scri...

Seems to me to tell you exactly what you are asking.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 1, 2009, 5:22am UTC](https://www.ruby-forum.com/t/autocomplete-fill-in-text-fields/169082/5 "2009-06-01T05:22:36Z")

</div>

Actually, sorry, that page indeed didn’t answer your question. Try this  
one though. Googled for “rails autocomplete multiple values”

> **[Multiple Values from Scriptaculous' Autocomplete - Journal - Wayne...](http://wayne-robinson.com/journal/2006/11/11/multiple-values-from-scriptaculous-autocomplete.html)**
>
> Ever wanted to extract multiple values from a Script.aculo.us Google Suggest-like autocomplete tex...

This is not something I’ve done myself before though, sorry.

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 1, 2009, 5:51am UTC](https://www.ruby-forum.com/t/autocomplete-fill-in-text-fields/169082/6 "2009-06-01T05:51:52Z")

</div>

WOW, that is cool. I cannot thank you enough. I guess I will learn to  
google properly. Never though of asking for the obvious. DOH!!

On Sun, May 31, 2009 at 10:22 PM, Jonathan R. \<

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [June 1, 2009, 5:19am UTC](https://www.ruby-forum.com/t/autocomplete-fill-in-text-fields/169082/7 "2009-06-01T05:19:43Z")

</div>

OK, pardon my ignorance I guess. Should I do set an instance variable  
for the output then use that in the RJS to populate the rest of the  
text\_fields with the other data? Seems that is the way to go.

On May 31, 9:56 pm, Jonathan R. \<rails-mailing-l…@andreas-
