# Radio\_button\_tag

**URL:** <https://www.ruby-forum.com/t/radio-button-tag/116947>\
**Category:** Rails\
**Created:** [October 11, 2007, 2:50pm UTC](https://www.ruby-forum.com/t/radio-button-tag/116947 "2007-10-11T14:50:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![crazybass](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@crazybass](https://www.ruby-forum.com/u/crazybass)\
**Post date:** [October 11, 2007, 2:50pm UTC](https://www.ruby-forum.com/t/radio-button-tag/116947/1 "2007-10-11T14:50:09Z")

</div>

Hello

I have a view which have 2 radio buttons :

…

Actuel \<%= radio\_button\_tag(:actuel, value = "1", checked = false, options = {}) %\> Last \<%= radio\_button\_tag(:last, value = "1", checked = false, options = {}) %\> ...

I dont know how to proceed to control the status of my radio buttons.  
When I click on the first one, i want to put the 2nd unchecked. When I  
click on the 2nd one I want to uncheck the first one.

I know how to to it using html radio buttons + javascript. But using  
radio\_button\_tag I dont know how to proceed.  
Anyone can help me please?

thanks  
regards

---

<div class="post-metadata">

**Author:** ![crazybass](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@crazybass](https://www.ruby-forum.com/u/crazybass)\
**Post date:** [October 11, 2007, 3:28pm UTC](https://www.ruby-forum.com/t/radio-button-tag/116947/2 "2007-10-11T15:28:54Z")

</div>

Paulo C. wrote:

> Hello
> 
> I have a view which have 2 radio buttons :
> 
> …
> 
> Actuel \<%= radio\_button\_tag(:actuel, value = "1", checked = false, options = {}) %\> Last \<%= radio\_button\_tag(:last, value = "1", checked = false, options = {}) %\> ...
> 
> I dont know how to proceed to control the status of my radio buttons.  
> When I click on the first one, i want to put the 2nd unchecked. When I  
> click on the 2nd one I want to uncheck the first one.
> 
> I know how to to it using html radio buttons + javascript. But using  
> radio\_button\_tag I dont know how to proceed.  
> Anyone can help me please?
> 
> thanks  
> regards

I had put the radio buttons with the same name to be on the same group.

actuel \<%= radio\_button\_tag(:type\_recherche, value = "1", checked = false, options = {}) %\> last \<%= radio\_button\_tag(:type\_recherche, value = "2", checked = false, options = {}) %\>

To pass the values I use a link\_to\_remote:

\<%= link\_to\_remote “Rechercher”,  
:update =\> “resultlist”,  
:url =\> { :action =\> ‘rechercher’},  
:with =\> “…+ ‘&’ +  
‘type\_recherche=’ + $F(‘type\_recherche’)”,  
:complete =\> visual\_effect(:appear, ‘resultlist’, :duration =\> 1.00)  
%\>

In my controller when i try to access to the “type\_recherche” value (my  
2 radio buttons), I do this:

if params[:type\_recherche].nil?  
puts “1”  
@demand.type\_recherche = “0”  
else  
if params[:type\_recherche].to\_s == ‘null’  
@demand.type\_recherche = “0”  
else  
puts "6 -\> " + params[:type\_recherche].to\_s  
@demand.type\_recherche = params[:type\_recherche]  
end  
end

When i check the first radio it works fine. I receive the value “1”. But  
when i check the second radio button, i always receive null. It seems  
that the only radio button used is the first one.

Any idea about this problem.

Thanks
