# Observe\_field radio

**URL:** <https://www.ruby-forum.com/t/observe-field-radio/91094>\
**Category:** Rails\
**Created:** [April 4, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/observe-field-radio/91094 "2007-04-04T17:04:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [April 4, 2007, 5:04pm UTC](https://www.ruby-forum.com/t/observe-field-radio/91094/1 "2007-04-04T17:04:24Z")

</div>

Hello,

I’m having trouble with observe\_field and radio buttons. The issue is  
the observe\_field action only fires the first time, subsequent clicks on  
radio buttons do nothing.

I’ve seen others post on this issue, but have not found any solutions.

CODE:

from view…

\<%= radio\_button\_tag(‘types’, ‘p5p’, (params[:dbinfo] ||= true))  
%\>P5P  
\<%= radio\_button\_tag(‘types’, ‘p5i’, false) %\>P5I

\<%= observe\_field(:types\_p5p,  
:udpate =\> ‘categories’,  
:url =\> {:action =\> ‘update\_module\_categories’},  
:with =\> “‘types=’ + encodeURIComponent(value)”,  
:on =\> ‘click’ ) %\>  
\<%= observe\_field(:types\_p5i,  
:udpate =\> ‘categories’,  
:url =\> {:action =\> ‘update\_module\_categories’},  
:with =\> “‘types=’ + encodeURIComponent(value)”,  
:on =\> ‘click’ ) %\>

###############

This works the first time I click one of the radios, but never again.

Any ideas?

regards,

Andy K.

---

<div class="post-metadata">

**Author:** ![ddancer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ecb155/32.png) [@ddancer](https://www.ruby-forum.com/u/ddancer)\
**Post date:** [April 4, 2007, 5:18pm UTC](https://www.ruby-forum.com/t/observe-field-radio/91094/2 "2007-04-04T17:18:25Z")

</div>

Andy K. schrieb:

> from view…  
> \<%= observe\_field(:types\_p5i,
> 
> regards,
> 
> Andy K.
> 
> >

In proper fashion I’ve solved my own problem. To save the next person  
from following yet another fruitless thread I’ll post it. However, this  
comes with a caveat that I don’t think this is a “best practices”  
solution. It does work, nonetheless.

Instead of using observe\_field, which I’m concluding does not work  
properly with radio buttons; till someone tells me otherwise, I’ve  
embedded the AJAX call into the radio.

Code being better than talk:

\<%= radio\_button\_tag(‘types’, ‘p5p’, (params[:dbinfo] ||= true),  
{:onclick =\> “{new  
Ajax.Updater(‘categories’,’/public/update\_module\_categories’,  
{asynchronous:true, evalScripts:true, parameters:‘types=’ +  
encodeURIComponent(value)})}”}) %\>P5P

\<%= radio\_button\_tag(‘types’, ‘p5i’, false, {:onclick =\> “{new  
Ajax.Updater(‘categories’,’/public/update\_module\_categories’,  
{asynchronous:true, evalScripts:true, parameters:‘types=’ +  
encodeURIComponent(value)})}”}) %\>P5I

…  
Thus, I first generated the AJAX code via the observe\_field method.  
Then I copied out the relevant portions from the HTML source code and  
pasted into the ‘onclick’ option of the radio button. Then deleted the  
observe\_field from the rhtml as it was now dead code.

It may not be pretty, but I can move to the next problem.

regards,

/ak
