# Observer not working for checkbox

**URL:** <https://www.ruby-forum.com/t/observer-not-working-for-checkbox/137823>\
**Category:** Rails\
**Created:** [May 16, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-checkbox/137823 "2008-05-16T17:25:48Z")\
**Posts on this page:** 5\
**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 16, 2008, 5:25pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-checkbox/137823/1 "2008-05-16T17:25:48Z")

</div>

Hi,

My code is like this:  
\<%= check\_box\_tag(“criteria[#{count}][data\_auto\_complete]”, “1”,true)  
%\>Private

\<%= observe\_field(“criteria[#{count}][data\_auto\_complete]”,  
:url =\> { :action =\>  
:choose\_auto\_complete\_selection, :type\_id =\> type\_id, :count =\> count,  
:report\_key =\> report\_key, :rcolumn =\> rcolumn, :data\_elem =\> @data\_elem  
},  
:before =\>  
“Element.show(‘indicator\_choose\_select\_all\_#{count}’)”,  
:success =\>  
“Element.hide(‘indicator\_choose\_select\_all\_#{count}’);  
document.getElementById(’\_commit’).disabled =false;”,  
:with =\> “‘value=’+value”) %\>

But the observer is not firing when i change the state of the check box.

Another thing is that this code is coming in a partial that is rendered  
in a window created using extjs new Window.

Any suggestions why the observer wont work but the onclick event works.

---

<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 16, 2008, 6:12pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-checkbox/137823/2 "2008-05-16T18:12:00Z")

</div>

It may be redundant, but you might try adding:  
:on=\>‘click’  
:frequency=\>0.25

onClick is supposed to be the default for check boxes but it won’t  
hurt to make it explicit. If that doesn’t help, setting the frequency  
will make the detection time-based rather than event-based and help  
make sure the change in value is detected.

On May 16, 11:25 am, 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 16, 2008, 6:14pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-checkbox/137823/3 "2008-05-16T18:14:08Z")

</div>

Still it didn’t work…  
AndyV wrote:

> It may be redundant, but you might try adding:  
> :on=\>‘click’  
> :frequency=\>0.25
> 
> onClick is supposed to be the default for check boxes but it won’t  
> hurt to make it explicit. If that doesn’t help, setting the frequency  
> will make the detection time-based rather than event-based and help  
> make sure the change in value is detected.
> 
> On May 16, 11:25 am, 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 16, 2008, 9:26pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-checkbox/137823/4 "2008-05-16T21:26:43Z")

</div>

Have you checked the rendered HTML to see if it looks to be correct  
and the id’s are matching up the way you expect? If those are  
matching then my guess would be that the js itself has an error.  
Check it in FF w/Firebug.

On May 16, 12:14 pm, 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 16, 2008, 9:29pm UTC](https://www.ruby-forum.com/t/observer-not-working-for-checkbox/137823/5 "2008-05-16T21:29:25Z")

</div>

AndyV wrote:

> Have you checked the rendered HTML to see if it looks to be correct  
> and the id’s are matching up the way you expect? If those are  
> matching then my guess would be that the js itself has an error.  
> Check it in FF w/Firebug.
> 
> On May 16, 12:14 pm, Neha C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Here is the javascript that is getting generated:
