# Field observer not working

**URL:** <https://www.ruby-forum.com/t/field-observer-not-working/71918>\
**Category:** Rails\
**Created:** [October 12, 2006, 12:21pm UTC](https://www.ruby-forum.com/t/field-observer-not-working/71918 "2006-10-12T12:21:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [October 12, 2006, 12:21pm UTC](https://www.ruby-forum.com/t/field-observer-not-working/71918/1 "2006-10-12T12:21:01Z")

</div>

Hello all.

I have the following snippet of code in a page of mine. As you can see  
it is two select boxes without a surrounding form.

Filter by client \<%= select('client','selection', Client.find(:all, :order =\> 'name').collect {|c| [c.name, c.id] }, :include\_blank =\> true ) %\> Select project \<%= select('project','selection', Project.find(:all, :order =\> 'name').collect {|p| [p.name, p.id] }, :include\_blank =\> true ) %\>

I am trying to setup an observer on the first field using the following:

\<%= observe\_field(“client\_selection”, :update =\> “project\_selection”,  
:url =\> {:action =\> :reload\_projects}, :with =\> “‘id=’+escape(value)”)  
%\>

The idea is that when the user selects a client only the client’s  
projects are displayed as options in the second select box. However I am  
coming across a JavaScript error. Not knowing much about JavaScript (Not  
enough to dbug prototype.js anyway!) I am rather stuck. FireBug gives me  
the following javascript trace:

element has no properties  
prototype.js?1159… (line 1506)  
anonymousprototype.js?1159… (line 1506)  
anonymousprototype.js?1159… (line 1658)  
anonymousprototype.js?1159… (line 1615)  
anonymousprototype.js?1159… (line 20)  
nullhttp://localhost:… (line 14)

As far as I can see I haven’t done anything totally out of whack on the  
RoR side. I am running on Edge Rails so am not sure if it is me or an  
issue in Edge (Or prototype.js).

Any help would be much appreciated.

RJ

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [October 12, 2006, 2:28pm UTC](https://www.ruby-forum.com/t/field-observer-not-working/71918/2 "2006-10-12T14:28:37Z")

</div>

Can you post the resulting action and RJS code? It looks like you’re  
referencing a DOM element that doesn’t exist (misspelled?).

Jason

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [October 12, 2006, 3:24pm UTC](https://www.ruby-forum.com/t/field-observer-not-working/71918/3 "2006-10-12T15:24:53Z")

</div>

Jason R. wrote:

> Can you post the resulting action and RJS code? It looks like you’re  
> referencing a DOM element that doesn’t exist (misspelled?).
> 
> Jason

Hi Jason.

this is the first time I have used field observers and RJS so I haven’t  
written the resulting action yet. The first step was to get the observer  
working and contacting the server.

Currently it isn’t calling the server when the field changes.

I assume that I don’t have to worry about the resulting action until I  
can verify that the server action is being called.

If not then I’ll get to it.

Thanks

RJ

---

<div class="post-metadata">

**Author:** ![RJRJRJ](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8491ac/32.png) [@RJRJRJ](https://www.ruby-forum.com/u/RJRJRJ)\
**Post date:** [October 18, 2006, 10:38am UTC](https://www.ruby-forum.com/t/field-observer-not-working/71918/4 "2006-10-18T10:38:52Z")

</div>

Hmm, it looks ok, though the :with syntax may be a problem. For the  
record,  
you don’t need :with if it’s dealing with just a field, Rails knows what  
you’re trying to do.

Can you post the resulting HTML? That will help solve this.

Jason
