# Showing options on radio button click

**URL:** <https://discuss.rubyonrails.org/t/showing-options-on-radio-button-click/7444>\
**Category:** rubyonrails-talk\
**Created:** [January 19, 2007, 2:19pm UTC](https://discuss.rubyonrails.org/t/showing-options-on-radio-button-click/7444 "2007-01-19T14:19:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miked](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Miked](https://discuss.rubyonrails.org/u/Miked)\
**Post date:** [January 19, 2007, 2:19pm UTC](https://discuss.rubyonrails.org/t/showing-options-on-radio-button-click/7444/1 "2007-01-19T14:19:55Z")

</div>

Hello:

I have four radio buttons, each mutually exclusive. I want to show a div area somewhere else on the page when one of these radio buttons is clicked. I know how to do that in HTML - how do I do that in rails? Here's one of my radio buttons:

\<%= f.radio\_button (:goaltype\_id, 1) %\>&nbsp;&nbsp;One-Time\<br\>

Thank you very much in advance!

Mike

---

<div class="post-metadata">

**Author:** ![Bill\_Walton](https://avatars.discourse-cdn.com/v4/letter/b/f07891/32.png) [@Bill\_Walton](https://discuss.rubyonrails.org/u/Bill_Walton)\
**Post date:** [January 19, 2007, 3:16pm UTC](https://discuss.rubyonrails.org/t/showing-options-on-radio-button-click/7444/2 "2007-01-19T15:16:11Z")

</div>

Hi Mike,

Miked wrote:

> I want to show a div area somewhere else on the page when one of these radio buttons is clicked.

If you're talking about an Ajax-style update, as a first step, you should take a look at the form types that do that (i.e., submit using XMLHttpRequest). From there, updating a specific div on a page is pretty much a slam dunk using RJS. I strongly recommend Cody Fauser's RJS tutorial on O'Reilly to get your feet wet in that area. Best $10 you'll spend on learning Rails.

hth, Bill

---

<div class="post-metadata">

**Author:** ![Miked](https://avatars.discourse-cdn.com/v4/letter/m/ed655f/32.png) [@Miked](https://discuss.rubyonrails.org/u/Miked)\
**Post date:** [January 19, 2007, 3:46pm UTC](https://discuss.rubyonrails.org/t/showing-options-on-radio-button-click/7444/3 "2007-01-19T15:46:40Z")

</div>

Hi Bill:

Thanks so much for your reply. I was looking into the XMLHttpRequest but I'm not finding in the rails api. I definitely want to use the ajax method. I've only seen it attached to a submit tag though - can I use it with a radio button as well? Definitely something I want to do. I'm also going to use that book - it looks great, but no time for that until the weekend!

So here's the code:

\<% form\_remote\_tag :url =\> { :action =\> :goaltype, :id =\> product } do %\> &nbsp;&nbsp;\<%= f.radio\_button ("Goal", "radio", "onetime") %\>&nbsp;&nbsp;One-Time\<br\> \<% end %\>

And then the RJS code:

page.replace\_html("goaltype" , :partial =\> "goal\_type")

But what happens in the controller method, since all I really want it to do is render the partial?

Thanks again.

Mike
