Field observer not working

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

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

Jason

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

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