# Odd behavior from the respectable replace\_html and his lovel

**URL:** <https://www.ruby-forum.com/t/odd-behavior-from-the-respectable-replace-html-and-his-lovel/109582>\
**Category:** Rails\
**Created:** [July 17, 2007, 2:47am UTC](https://www.ruby-forum.com/t/odd-behavior-from-the-respectable-replace-html-and-his-lovel/109582 "2007-07-17T02:47:37Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrei](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9fc29f/32.png) [@andrei](https://www.ruby-forum.com/u/andrei)\
**Post date:** [July 17, 2007, 2:47am UTC](https://www.ruby-forum.com/t/odd-behavior-from-the-respectable-replace-html-and-his-lovel/109582/1 "2007-07-17T02:47:37Z")

</div>

Hello there, kind RoR folk. I have a wee bit of a pickle, so i’ll get  
straight to the point.

In one of my views i have two matching dropdowns containing teams.  
Upon the changing of the selection, provided that the two are  
different, my desire is to spawn another dropdown containing referees.  
Below is the view code for one of the dropdowns. The other one is  
strikingly similar.

\<%= form.collection\_select “first\_team\_id”, @teams, :id, :name, {}, {  
:onchange =\> remote\_function( :update =\> “referees”,  
:url =\> { :action =\>  
“update\_referees” },  
:with =\> “‘match[first\_team\_id]=’ +  
this.value + ‘&match[second\_team\_id]=’ + $  
(‘match\_second\_team\_id’).value”,  
:condition =\> “this.value != $  
(‘match\_second\_team\_id’).value”  
)  
} %\>

The dropdown is contained in a partial aptly named “referees”, and as  
to my best knowledge, i have populated a rjs file associated to the  
‘update\_referees’ action with the following:

page[:referees].replace\_html :partial =\> “referees”

This, however, fails to produce the expected result and instead just  
spews the javascript inside my lovely ‘referees’ layer. However, being  
a persistent individual, i altered the .rjs to

page[:referees].replace :partial =\> “referees”

Unexpectedly, this does actually produce a dropdown, but unfortunately  
also destroys my layer and with it any hope i would have to rebuild my  
dropdown in case the team selection is altered.

After some hours of scraping through documentation and debugging  
prototype i noticed that Ajax.Updater actually runs through the code  
twice, first upon receiving it, and subsequently within the  
“updateContent” method. Sadly, however, on the first run of the code  
everything is left in order and fully peachy, but after the  
“updateContent” method, my previously cheery layer is filled with  
javascript.

If you’ve made it thus far, first of all i’d like to thank you for  
being so patient, and second i would like to ask whether i am doing  
something that i’m not supposed to or prototype is goofing.

Many thanks,  
Andrei
