Forum: Ruby on Rails Observe Field Problem

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Enzo R. (Guest)
on 2009-02-14 01:39
Hi there!

I need to use observe field to change dynamically one select field based
on another select field:

here is the view:

<%= observe_field 'class', :url => { :action => 'update_list' },
          :frequency => 0.25,
          :update => 'nickname',
                      :with => 'tipid'

Class:<select name="<%= "#{name}[][#{name}_class]" %>" id="class">
      <%= options_from_collection_for_select(Tiprod.find(:all),
"id","name", {:include_blank => true}) %>
Name:<select name="<%= "#{name}[][#{name}_data]" %>" id="nickname">

here is the controller

def update_list
  @tipid = params[:tipid]
  @products = Specprod.find(:all, :conditions => ['tiprif LIKE ?',

and here is the update_list.rhtml

<% for product in @products%>
  <option value="<%= %>"><%=></option>
<% end %>

inspired by:

Now, when i try to fire this application, the script doesn't work, and
the JS console tell me "Element is null" .
Why?Where i was wrong?

thanks in advance for the help
Frederick C. (Guest)
on 2009-02-14 12:32
(Received via mailing list)
On Feb 13, 11:39 pm, Enzo R. <removed_email_address@domain.invalid>
>                       :with => 'tipid'
> here is the controller
>   <option value="<%= %>"><%=></option>
> <% end %>
> inspired by:

The observe_field helper just produces some javascript that does stuff
to the element with id class

You've got the call to observe_field before your select element, ie
it's trying to observe something that doesn't exist yet.

This topic is locked and can not be replied to.