# Help with selection list

**URL:** <https://www.ruby-forum.com/t/help-with-selection-list/112390>\
**Category:** Rails\
**Created:** [August 18, 2007, 7:23am UTC](https://www.ruby-forum.com/t/help-with-selection-list/112390 "2007-08-18T07:23:21Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 18, 2007, 7:23am UTC](https://www.ruby-forum.com/t/help-with-selection-list/112390/1 "2007-08-18T07:23:21Z")

</div>

Hi,

I want to make a selection list, which I call a dropdown, which, when  
a user makes his or her selection, will do an ajax call, and update a  
partial. Without hitting a button – the ajax request will fire off  
upon the selection.

I’d appreciate a hint – can’t figure out where to start.

Charlie

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 18, 2007, 9:17am UTC](https://www.ruby-forum.com/t/help-with-selection-list/112390/2 "2007-08-18T09:17:27Z")

</div>

Charlie,

The Agile Book is always a good place to start looking for things  
Rails. In your case, page 523-526 in the 2nd Edition has some good  
stuff that can get you started on what you want.

Regards,  
Rajesh

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 18, 2007, 6:05pm UTC](https://www.ruby-forum.com/t/help-with-selection-list/112390/3 "2007-08-18T18:05:38Z")

</div>

Is a form observer the way to go with this? I was thinking of just  
doing an onchange, so that when any element is selected, it fires off  
an ajax request.

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 18, 2007, 7:21pm UTC](https://www.ruby-forum.com/t/help-with-selection-list/112390/4 "2007-08-18T19:21:42Z")

</div>

Either way would work. I prefer to write less javascript and let the  
observer deal w/ the ajax request, but they will both do basically the  
same thing one is a little more rails, the other a little more  
javascript.

charlie caroff wrote:

> > stuff that can get you started on what you want.
> > 
> > > a user makes his or her selection, will do an ajax call, and update a

–  
Sincerely,

William P.

[http://www.billpratt.net](http://www.billpratt.net)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 18, 2007, 7:23pm UTC](https://www.ruby-forum.com/t/help-with-selection-list/112390/5 "2007-08-18T19:23:42Z")

</div>

I use observers for this all the time doing exactly what you want. I use  
it in my pagination footer. I give the user a list of available pages,  
and if a new page is chosen, the observer fires off an ajax request  
which then uses rjs to update the page results.

K. Rajesh wrote:

> > 
> 
> >

–  
Sincerely,

William P.

[http://www.billpratt.net](http://www.billpratt.net)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 18, 2007, 7:55pm UTC](https://www.ruby-forum.com/t/help-with-selection-list/112390/6 "2007-08-18T19:55:47Z")

</div>

By way of an example:

The default for observe field is on change so the call to remote  
occurs whenever a selection is made:

```
   <%= select 'order', 'ship_method',
     ['1st Class Standard', '1st Class Recorded','Next Day

```

Courier’, ‘Special Delivery’ ]%\>

…

\<%= observe\_field :order\_ship\_method,  
:url=\>url\_for(:action=\>:edit\_batch\_field,  
:controller=\>‘order’, :id=\>@order.id),  
:with=\>“ship\_method”

```
              %>

```

hth  
Tonypm

---

<div class="post-metadata">

**Author:** ![charlie\_caroff](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a587f6/32.png) [@charlie\_caroff](https://www.ruby-forum.com/u/charlie_caroff)\
**Post date:** [August 18, 2007, 9:12pm UTC](https://www.ruby-forum.com/t/help-with-selection-list/112390/7 "2007-08-18T21:12:52Z")

</div>

Very good. Thanks to all. This is one of those things where I didn’t  
know what to look for in the first place. Got it working now.
