observe_field not updating DOM

Hi-

I'm trying to implement the elusive country-state connected select boxes.

I have a controller:

... def get_states     @states = State.find(:all, :conditions => {:country_id => 1})     render :partial => "state_options"   end

(this is the ajax call)

and a template:

<% form_for :user, @user, :url => { :action => "create" } do |form| %>   <%= render :partial => 'form', :locals => { :form => form, :genders => @genders} %>   <%= submit_tag "Create" %> <%end%> <%= observe_field("user_country", :url => {:action => :get_states,:update => "mydiv"}) %> <%end%>

and a partial, which simply generates the <option></option> tags in between the <select></select> tags.

the first time it's rendered, it creates an empty <select> pair:

... <p> <label> State<br/> <select id="user_state" name="user[state]"></select> </label> </p> ...

If I enter the partial URL directly into the browser, it works. If I replace the observe_field target with a simple alert javascript function, it works, so I know the syntax and partial are correct. The problem is, it just won't update the web browser page. I never see any change.

Any ideas why?

Thanks, Dino

=> :get_states,:update => "mydiv"}) %> <===== OOPS , should say:

<%= observe_field("user_country", :url => {:action => :get_states}, :update => "user_states") %>

Hi Dino,

I can only see a "user_state" id (<select id="user_state" name="user[state]"></select>), not a "user_states" id as you described above.

Have you tried using the Firebug add-on for Firefox? I would definitely recommend it when trying to debug AJAX requests.

Jabbslad

Thanks Jabbslad-

It was not quite this, but it was a naming issue. Thanks for your help. Dino