# Observe\_field not updating DOM

**URL:** <https://www.ruby-forum.com/t/observe-field-not-updating-dom/130399>\
**Category:** Rails\
**Created:** [February 27, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/observe-field-not-updating-dom/130399 "2008-02-27T23:06:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 27, 2008, 11:06pm UTC](https://www.ruby-forum.com/t/observe-field-not-updating-dom/130399/1 "2008-02-27T23:06:32Z")

</div>

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 tags in  
between the tags.

the first time it’s rendered, it creates an empty pair:

…

State

...

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

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 27, 2008, 11:37pm UTC](https://www.ruby-forum.com/t/observe-field-not-updating-dom/130399/2 "2008-02-27T23:37:16Z")

</div>

=\> :get\_states,:update =\> “mydiv”}) %\> \<=====  
OOPS , should say:

\<%= observe\_field(“user\_country”, :url =\> {:action  
=\> :get\_states}, :update =\> “user\_states”) %\>

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 28, 2008, 1:16am UTC](https://www.ruby-forum.com/t/observe-field-not-updating-dom/130399/3 "2008-02-28T01:16:32Z")

</div>

Hi Dino,

I can only see a “user\_state” id (), 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

---

<div class="post-metadata">

**Author:** ![dino\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/b5ac83/32.png) [@dino\_d](https://www.ruby-forum.com/u/dino_d)\
**Post date:** [February 28, 2008, 9:17pm UTC](https://www.ruby-forum.com/t/observe-field-not-updating-dom/130399/4 "2008-02-28T21:17:37Z")

</div>

Thanks Jabbslad-

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