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 ?’,
“%{@tipid}%”])
end
and here is the update_list.rhtml
<% for product in @products%>
<%= product.name%> <% end %>inspired by:
http://nealenssle.com/blog/2007/04/12/how-to-dynamically-update-form-elements-in-rails-using-ajax/
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