# Observer with group of radio buttons

**URL:** <https://www.ruby-forum.com/t/observer-with-group-of-radio-buttons/130609>\
**Category:** Rails\
**Created:** [February 29, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/observer-with-group-of-radio-buttons/130609 "2008-02-29T19:53:03Z")\
**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:** [February 29, 2008, 7:53pm UTC](https://www.ruby-forum.com/t/observer-with-group-of-radio-buttons/130609/1 "2008-02-29T19:53:03Z")

</div>

Hi,

My code looks like this  
\<%get\_date\_ranges().each{|arr|%\>  
  
\<%=arr[1]%\>  
  
\<%}%\>

\<%= observe\_field(“criteria[#{count}]”,  
:url =\> { :action =\> :date\_range, :count =\>  
count,:type\_id =\> type\_id, :report\_key =\> report\_key },  
:frequency =\> 3,  
:with =\> “‘type\_id=’+value”) %\>  
I have a group of radio buttons and i want the observer to fire an  
action when any radio button is checked.  
But the observer is not working. Can someone suggest what could be the  
possible reason for it not to work.

Neha

---

<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:** [February 29, 2008, 8:46pm UTC](https://www.ruby-forum.com/t/observer-with-group-of-radio-buttons/130609/2 "2008-02-29T20:46:05Z")

</div>

On 2/29/08, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> \<%= observe\_field(“criteria[#{count}][date\_range]”,  
> :url =\> { :action =\> :date\_range, :count =\>  
> count,:type\_id =\> type\_id, :report\_key =\> report\_key },  
> :frequency =\> 3,  
> :with =\> “‘type\_id=’+value”) %\>  
> I have a group of radio buttons and i want the observer to fire an  
> action when any radio button is checked.  
> But the observer is not working. Can someone suggest what could be the  
> possible reason for it not to work.

Well you seem to have a loop which generates multiple buttons all  
apparently with the same id (which should be unique), then you set up  
one observer after the loop.

–  
Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<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:** [February 29, 2008, 10:10pm UTC](https://www.ruby-forum.com/t/observer-with-group-of-radio-buttons/130609/3 "2008-02-29T22:10:03Z")

</div>

But if i have a group of radio buttons, they should have the same id  
so that they form a group  
Also if i give them different ids then on what will my observer field  
act?

---

<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:** [February 29, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/observer-with-group-of-radio-buttons/130609/4 "2008-02-29T23:13:13Z")

</div>

On 2/29/08, removed\_email\_address@domain.invalid [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> But if i have a group of radio buttons, they should have the same id  
> so that they form a group  
> Also if i give them different ids then on what will my observer field  
> act?

No it’s the name which groups the buttons:  
[http://www.echoecho.com/htmlforms10.htm](http://www.echoecho.com/htmlforms10.htm)

Dom ids should be unique, or it’s quite likely that the browser will  
get confused at best.

## I think that you either need an observer for each button, or if they are in a form you can use observe\_form which will trigger when any element in the form changes.

Rick DeNatale

My blog on Ruby  
[http://talklikeaduck.denhaven2.com/](http://talklikeaduck.denhaven2.com/)

---

<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:** [February 29, 2008, 11:33pm UTC](https://www.ruby-forum.com/t/observer-with-group-of-radio-buttons/130609/5 "2008-02-29T23:33:20Z")

</div>

If i give them all different ids, then will it be possible to have a  
observe\_field on the name of the radio buttons  
as the number of buttons is quite high and i dont want to have a  
separate observer for each button as that will make the code quite  
cumbersome.  
And my form is being built up dynamically so i cant have observe\_form  
also.
