# Observe\_field and select lists

**URL:** <https://discuss.rubyonrails.org/t/observe-field-and-select-lists/2926>\
**Category:** rubyonrails-talk\
**Created:** [October 11, 2006, 9:44am UTC](https://discuss.rubyonrails.org/t/observe-field-and-select-lists/2926 "2006-10-11T09:44:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dark\_Ambient](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Dark\_Ambient](https://discuss.rubyonrails.org/u/Dark_Ambient)\
**Post date:** [October 11, 2006, 9:44am UTC](https://discuss.rubyonrails.org/t/observe-field-and-select-lists/2926/1 "2006-10-11T09:44:31Z")

</div>

I’m somewhat confused on how to set up a select list for observe\_field. Example :

\<%=options\_from\_collection\_for\_select @states, :id, :name %\>

I want ot get the values when the user chooses them from the list. The "search[state\_id] is not important as it’s from a regular search form. Just not sure how to name or id these lists so I can set up the observe\_field. Does my question make sense ?

Reading through some observe\_field examples I’ve seen for a text\_field it’s something like this :

```ruby
<%= text_field_tag("query", @params['query'], :size => 10 ) %>

```

Selects are the same ? (And yeah I should try it anyway before asking 🙂

Stuart

---

<div class="post-metadata">

**Author:** ![Ezra\_Zygmuntowicz](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Ezra\_Zygmuntowicz](https://discuss.rubyonrails.org/u/Ezra_Zygmuntowicz)\
**Post date:** [October 11, 2006, 5:36pm UTC](https://discuss.rubyonrails.org/t/observe-field-and-select-lists/2926/2 "2006-10-11T17:36:12Z")

</div>

\<select name="search[state\_id]" size="10" multiple="multiple" id='someid'\>

then observe field on 'someid'

-Ezra

---

<div class="post-metadata">

**Author:** ![Dark\_Ambient](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Dark\_Ambient](https://discuss.rubyonrails.org/u/Dark_Ambient)\
**Post date:** [October 11, 2006, 6:01pm UTC](https://discuss.rubyonrails.org/t/observe-field-and-select-lists/2926/3 "2006-10-11T18:01:52Z")

</div>

So it looks like there is no \<%= %\> erb ? tags surrounding the select ?

Is that correct ?

Stuart

---

<div class="post-metadata">

**Author:** ![Ezra\_Zygmuntowicz](https://avatars.discourse-cdn.com/v4/letter/e/958977/32.png) [@Ezra\_Zygmuntowicz](https://discuss.rubyonrails.org/u/Ezra_Zygmuntowicz)\
**Post date:** [October 11, 2006, 8:05pm UTC](https://discuss.rubyonrails.org/t/observe-field-and-select-lists/2926/4 "2006-10-11T20:05:57Z")

</div>

I'm not sure if we are talking about the same thing here. I was just saying that there is no id tag on your select tag so the observe fielkd has no dom id to observe. You don't have to use helpers to make the select but you do need an id on the select tag. Here ia a working example that I am using. I like to write out the form observer JS by hand though as it is more flexible:

\<%= select\_tag 'snapshot[version]', &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;options\_for\_select( @snapshot.versions.map{|v| v.version}, @selected\_snapshot.version), &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:id =\> 'snapshot\_select'%\>

&nbsp;&nbsp;\<script type="text/javascript"\> &nbsp;&nbsp;&nbsp;&nbsp;//\<![CDATA[&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Form.Element.EventObserver("snapshot\_select", function(element, value) { &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;new Ajax.Request('/apps/snapshot\_version/\<%= @app.id -%\>', {asynchronous:'true', evalScripts:'true', parameters:'version=' + value}) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}) &nbsp;&nbsp;&nbsp;&nbsp;//]]\> &nbsp;&nbsp;\</script\>

-Ezra

---

<div class="post-metadata">

**Author:** ![Dark\_Ambient](https://avatars.discourse-cdn.com/v4/letter/d/e9bcb4/32.png) [@Dark\_Ambient](https://discuss.rubyonrails.org/u/Dark_Ambient)\
**Post date:** [October 11, 2006, 9:24pm UTC](https://discuss.rubyonrails.org/t/observe-field-and-select-lists/2926/5 "2006-10-11T21:24:23Z")

</div>

No we are talking about the same thing. Thanks for your help. Clears up at least one piece of the puzzle. Stuart
