# Observer not working for select field

**URL:** <https://www.ruby-forum.com/t/observer-not-working-for-select-field/138302>\
**Category:** Rails\
**Created:** [May 21, 2008, 9:16pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-select-field/138302 "2008-05-21T21:16:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![neha-rohan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@neha-rohan](https://www.ruby-forum.com/u/neha-rohan)\
**Post date:** [May 21, 2008, 9:16pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-select-field/138302/1 "2008-05-21T21:16:09Z")

</div>

Hi,

My code is as follows:  
  
select one  
\<%Report.get\_criteria\_array(report.model\_list,  
session[:app\_user\_id], term\_type).each{|arr|%\>  
  
\<%=arr[1]%\>  
  
\<%}%\>  
  
\<%= observe\_field(“criteria[#{count}][type\_id]”,  
:function =\> “term\_selected(#{count},’#{report\_key}’)”)%\>

And the javascript that gets generated is:

select one Company Name 

But the observer doesnt fire whenever i select anything from the select  
list.

---

<div class="post-metadata">

**Author:** ![neha-rohan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@neha-rohan](https://www.ruby-forum.com/u/neha-rohan)\
**Post date:** [May 22, 2008, 4:29am UTC](https://www.ruby-forum.com/t/observer-not-working-for-select-field/138302/2 "2008-05-22T04:29:43Z")

</div>

Hi Neha,

Do you have Firebug installed? It would help (a lot) to know what JS it  
says is being generated.  
Best regards,  
Bill

---

<div class="post-metadata">

**Author:** ![neha-rohan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@neha-rohan](https://www.ruby-forum.com/u/neha-rohan)\
**Post date:** [May 22, 2008, 8:06am UTC](https://www.ruby-forum.com/t/observer-not-working-for-select-field/138302/3 "2008-05-22T08:06:08Z")

</div>

I believe that the observer on a select fires with “onChange” which  
means you have to tab out of the select before the observer will  
detect the change.

---

<div class="post-metadata">

**Author:** ![neha-rohan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@neha-rohan](https://www.ruby-forum.com/u/neha-rohan)\
**Post date:** [May 22, 2008, 10:22am UTC](https://www.ruby-forum.com/t/observer-not-working-for-select-field/138302/4 "2008-05-22T10:22:18Z")

</div>

I’ve tested it (with an alert call instead of term\_selected) and it  
works for me.  
Maybe there’s a javascript error in other part of the code?

On 21 maio, 16:16, Neha C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![neha-rohan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@neha-rohan](https://www.ruby-forum.com/u/neha-rohan)\
**Post date:** [May 22, 2008, 2:04pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-select-field/138302/5 "2008-05-22T14:04:00Z")

</div>

Fernando Lages wrote:

> I’ve tested it (with an alert call instead of term\_selected) and it  
> works for me.  
> Maybe there’s a javascript error in other part of the code?
> 
> On 21 maio, 16:16, Neha C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

My whole situation is like this:

I am using extjs for my tab layouts.  
When i am getting a tab to be loaded i am making a call to a method and  
from there i do  
if(some condition)  
render :partial=\>‘x’  
else  
render :partial=\>‘y’  
end

When partial ‘x’ is rendered, upon some successful completion of an ajax  
call i then render partial ‘y’ by doing

render :update do |page|  
page.replace\_html ‘div\_id’, :partial=\>‘y’  
end

Now the issue is in partial ‘y’ i have an observer and it gets fired if  
am coming to that partial from x and then y. But if i come to the y  
partial straightaway the observer is not getting fired at all.

Can someone help me with what could be the difference that is not  
letting the observer to fire.

So the observer works in all cases except for one.

---

<div class="post-metadata">

**Author:** ![neha-rohan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@neha-rohan](https://www.ruby-forum.com/u/neha-rohan)\
**Post date:** [May 22, 2008, 2:13pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-select-field/138302/6 "2008-05-22T14:13:42Z")

</div>

Bill W. wrote:

> Hi Neha,
> 
> Do you have Firebug installed? It would help (a lot) to know what JS it  
> says is being generated.  
> Best regards,  
> Bill

select one Company Name
