# Observing collection\_select + text\_field

**URL:** <https://www.ruby-forum.com/t/observing-collection-select-text-field/144663>\
**Category:** Rails\
**Created:** [July 31, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/observing-collection-select-text-field/144663 "2008-07-31T23:19:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 11:19pm UTC](https://www.ruby-forum.com/t/observing-collection-select-text-field/144663/1 "2008-07-31T23:19:00Z")

</div>

\<%= collection\_select(:category, :id, @categories, :id, :name, options ={:prompt =\> "-Select categories-"}, :class=\>"category\_dropdown\_list") %\> 

```
<td>
    <%= text_field_tag :search, params[:search], :id=>"search_form",

```

:value=\>params[:search] %\>

```
              <%= observe_field 'search_form',
                          :frequency => 0.5,
                          :url => { :controller => 'auth_user',

```

:action =\> ‘get\_results’ },  
:loading =\>  
“Element.show(‘indicator\_gif\_id’)”,  
:complete =\>  
“Element.hide(‘indicator\_gif\_id’)”,  
:with =\> “‘search\_text=’ + escape(value)”  
%\>

I can observe the text\_field, but how do I send the current selected  
value of the collection\_select also. :with =\> selected item in  
collection\_select

Thanks!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 11:22pm UTC](https://www.ruby-forum.com/t/observing-collection-select-text-field/144663/2 "2008-07-31T23:22:48Z")

</div>

Try observe\_field instead, and leave off the :with.

You don’t need :with most of the time unless you’re trying to change the  
field. See the API.

On Thu, Jul 31, 2008 at 4:19 PM, Justin To  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 11:35pm UTC](https://www.ruby-forum.com/t/observing-collection-select-text-field/144663/3 "2008-07-31T23:35:07Z")

</div>

On 31 Jul 2008, at 22:21, Brian H. wrote:

> Try observe\_field instead, and leave off the :with.
> 
> You don’t need :with most of the time unless you’re trying to change  
> the field. See the API.

You do need it if you want to submit more than one field. I wrote up  
some usages of :with a while back  
([:with or :without you: link\_to\_remote's mysterious parameter - Space Vatican](http://www.spacevatican.org/2008/5/17/with-or-without-you-link_to_remote-s-mysterious-parameter)  
)  
Depending on usage observe\_form may be a better fit.

Fred

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 11:37pm UTC](https://www.ruby-forum.com/t/observing-collection-select-text-field/144663/4 "2008-07-31T23:37:28Z")

</div>

Ooops should have phrased that differently. Fred’s explanation is great,  
as  
always.

On Thu, Jul 31, 2008 at 4:34 PM, Frederick C. \<

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 1, 2008, 9:31am UTC](https://www.ruby-forum.com/t/observing-collection-select-text-field/144663/5 "2008-08-01T09:31:00Z")

</div>

On Jul 31, 11:15 pm, Justin To [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> I read through your article Fred, but I’m still lost trying to figure  
> out how to pass the two values. How do I even access the values?
> 
> $(‘comment’).serialize()  
> Will evaluate to  
> comment=whatever\_is\_in\_the\_field\_with\_that\_id
> 
> I saw that in your article…so should I give the collection\_select and  
> text\_field id’s and use two of these: $(‘comment’).serialize()?

Yes. One of the examples given was :with =\> "$(‘message’).serialize()

- ‘&’ + $(‘comment’).serialize()"

Fred

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 1, 2008, 12:15am UTC](https://www.ruby-forum.com/t/observing-collection-select-text-field/144663/6 "2008-08-01T00:15:50Z")

</div>

I read through your article Fred, but I’m still lost trying to figure  
out how to pass the two values. How do I even access the values?

$(‘comment’).serialize()

I saw that in your article…so should I give the collection\_select and  
text\_field id’s and use two of these: $(‘comment’).serialize()?

Thanks

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 1, 2008, 7:05pm UTC](https://www.ruby-forum.com/t/observing-collection-select-text-field/144663/7 "2008-08-01T19:05:11Z")

</div>

Great, got it to work. Thanks a bunch Fred!
