# Observe\_field

**URL:** <https://www.ruby-forum.com/t/observe-field/140893>\
**Category:** Rails\
**Created:** [June 19, 2008, 3:39pm UTC](https://www.ruby-forum.com/t/observe-field/140893 "2008-06-19T15:39:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 19, 2008, 3:39pm UTC](https://www.ruby-forum.com/t/observe-field/140893/1 "2008-06-19T15:39:04Z")

</div>

I have been trying to pass a collection\_select parameter and a text  
field  
parameter to observe\_field so that it watches both the parameters  
simultaneously.

but what i can see is , when i select some value from drop down and dont  
write anything in text field its giving correct results.parameters are  
also  
correct passed, but just after that if i write something in text field  
that  
value also get passed as collection\_select parameter(labtid in my case)  
my view code is:

  

Filter on Device Name :   
\<%= text\_field\_tag(“query”, params[‘query’], :size =\> 10 )%\>

Lab :   
\<%= collection\_select(:labt, :labtid,  
@labs, :id, :name,:prompt =\> “Select a Lab”) %\>

\<%= image\_tag("spinner.gif", :align =\> "absmiddle", :border =\> 0, :id =\> "spinner", :style =\>"display: none;" ) %\>

\<%= javascript\_include\_tag :defaults %\>

\<%= observe\_field ‘query’, :frequency =\> 2,  
:update =\> “table”,  
:before =\> “Element.show(‘spinner’)”,  
:success =\> “Element.hide(‘spinner’)”,  
:url =\> {:action =\> ‘trial\_location1’},  
:with =\> “‘labtid=’ + value+‘&query=’+escape($(‘query’).value)”  
%\>  
\<%= observe\_field ‘labt\_labtid’, :frequency =\> 2,  
:update =\> “table”,  
:before =\> “Element.show(‘spinner’)”,  
:success =\> “Element.hide(‘spinner’)”,  
:url =\> {:action =\> ‘trial\_location1’},

```
     :with => "'labtid=' + value+'&query='+escape($('query').value)"

   %>

```

\<%= render :partial =\> "devices\_list" %\>

## i believe the problem lies with :with parameter. Can someone suggest me the problem? Thanking in advance!!

View this message in context:  
[http://www.nabble.com/observe\_field-tp18009235p18009235.html](http://www.nabble.com/observe_field-tp18009235p18009235.html)  
Sent from the RubyOnRails Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 19, 2008, 3:47pm UTC](https://www.ruby-forum.com/t/observe-field/140893/2 "2008-06-19T15:47:53Z")

</div>

On 19 Jun 2008, at 14:38, sup wrote:

> are also  
> :url =\> {:action =\> ‘trial\_location1’},  
> :with =\> “‘labtid=’ + value+’&query=’+escape($  
> (‘query’).value)” %\>  
> In the context of an observe\_field, value is the value of the observed  
> field (so $(‘query’).value in this case, and $(‘labt\_labtid’) in the  
> other, so you need to swap things around in the above observe\_form  
> (the other one is fine)  
> Might observe\_form not be less hassle in this case ?

Fred

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 19, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/observe-field/140893/3 "2008-06-19T15:56:48Z")

</div>

u mean it should be like this ?  
:with =\> “‘labt\_labtid=’ + value+’&query=’+escape($(‘query’).value)”

On Thu, Jun 19, 2008 at 7:17 PM, Frederick C. \<

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 19, 2008, 4:09pm UTC](https://www.ruby-forum.com/t/observe-field/140893/4 "2008-06-19T16:09:46Z")

</div>

On 19 Jun 2008, at 14:55, supriya agarwal wrote:

> u mean it should be like this ?  
> :with =\> “‘labt\_labtid=’ + value+’&query=’+escape($(‘query’).value)”

the observe field on labt\_labtid should be like that, but not the  
other one (again, it might be easier to have a single observe form)

Fred

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 20, 2008, 8:33am UTC](https://www.ruby-forum.com/t/observe-field/140893/5 "2008-06-20T08:33:13Z")

</div>

On Jun 20, 5:59 am, “supriya agarwal” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> i tried doing it this way… its working fine…  
> also i think i should tell you that in my controller im accessing labtid as  
> params[:labtid] .  
> i tried putting params[:labt][:labtid] but then it completely failed.

You need to name the parameter labt[labtid] in your :with option if  
you want to be able to access it as params[:labt][:labtid] as you do  
when it’s submitted ‘normally’

> can you help me here?? it would be great if you could put some sample code  
> for observe\_form . i have no clue how it should work.!

It’s just like observe\_field except you give it a form and it will  
submit the whole form whenever any of it changes.

Fred

---

<div class="post-metadata">

**Author:** ![supriyaiiita](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a9adbd/32.png) [@supriyaiiita](https://www.ruby-forum.com/u/supriyaiiita)\
**Post date:** [June 20, 2008, 7:00am UTC](https://www.ruby-forum.com/t/observe-field/140893/6 "2008-06-20T07:00:27Z")

</div>

i tried doing it this way… its working fine…  
also i think i should tell you that in my controller im accessing labtid  
as  
params[:labtid] .  
i tried putting params[:labt][:labtid] but then it completely failed.

can you help me here?? it would be great if you could put some sample  
code  
for observe\_form . i have no clue how it should work.!

Thanks again alot!

On Thu, Jun 19, 2008 at 7:39 PM, Frederick C. \<
