# Radio\_button

**URL:** <https://www.ruby-forum.com/t/radio-button/109153>\
**Category:** Rails\
**Created:** [July 11, 2007, 11:25pm UTC](https://www.ruby-forum.com/t/radio-button/109153 "2007-07-11T23:25:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 11, 2007, 11:25pm UTC](https://www.ruby-forum.com/t/radio-button/109153/1 "2007-07-11T23:25:56Z")

</div>

I want to create an onclick event for the radio button. Here is what I  
have:

\<%= radio\_button\_tag ‘user’, ‘d\_home’, :id =\> ‘user[d\_home]’, :onclick  
=\> “new Effect.SwitchOff(‘apear-div’); new Effect.Fade( ‘apear-div’ )”  
%\>

Now, the radio button works fine along with the other members of the  
group, is just doesn’t recognize the :onclick part. Anyone know what I’m  
missing here? Thanks,

–S

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 12, 2007, 12:11pm UTC](https://www.ruby-forum.com/t/radio-button/109153/2 "2007-07-12T12:11:52Z")

</div>

Shandy N. wrote:

> I want to create an onclick event for the radio button. Here is what I  
> have:
> 
> \<%= radio\_button\_tag ‘user’, ‘d\_home’, :id =\> ‘user[d\_home]’, :onclick  
> =\> “new Effect.SwitchOff(‘apear-div’); new Effect.Fade( ‘apear-div’ )”  
> %\>
> 
> Now, the radio button works fine along with the other members of the  
> group, is just doesn’t recognize the :onclick part. Anyone know what I’m  
> missing here? Thanks,

Check the APIs for radio\_button and radio\_button\_tag, you’re not  
using them correctly:

> **[ActionView::Helpers::FormHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#M000502)**
>
> Form helpers are designed to make working with resources much easier compared to using vanilla HTML.

> **[ActionView::Helpers::FormTagHelper](https://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#M000611)**
>
> Provides a number of methods for creating form tags that don't rely on an Active Record object assigned to the template like FormHelper does. Instead, you provide the names and values manually.

–  
We develop, watch us RoR, in numbers too big to ignore.

---

<div class="post-metadata">

**Author:** ![snantz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c2a13f/32.png) [@snantz](https://www.ruby-forum.com/u/snantz)\
**Post date:** [July 12, 2007, 12:30pm UTC](https://www.ruby-forum.com/t/radio-button/109153/3 "2007-07-12T12:30:09Z")

</div>

Shandy N. wrote:

> I want to create an onclick event for the radio button. Here is what I  
> have:
> 
> \<%= radio\_button\_tag ‘user’, ‘d\_home’, :id =\> ‘user[d\_home]’, :onclick  
> =\> “new Effect.SwitchOff(‘apear-div’); new Effect.Fade( ‘apear-div’ )”  
> %\>
> 
> Now, the radio button works fine along with the other members of the  
> group, is just doesn’t recognize the :onclick part. Anyone know what I’m  
> missing here? Thanks,
> 
> –S

Try this, it should work (note (a) checked attribute ‘true’ (b) options  
within ‘{’ and ‘}’):

\<%= radio\_button\_tag ‘user’, ‘d\_home’, true, {:id =\> ‘user[d\_home]’,  
:onclick =\> “new Effect.SwitchOff(‘apear-div’); new Effect.Fade(  
‘apear-div’ )”} %\>

Roberto Gattinoni.
