# Help Radio button

**URL:** <https://www.ruby-forum.com/t/help-radio-button/227061>\
**Category:** Rails\
**Created:** [March 2, 2013, 6:34pm UTC](https://www.ruby-forum.com/t/help-radio-button/227061 "2013-03-02T18:34:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NN\_Dodhia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@NN\_Dodhia](https://www.ruby-forum.com/u/NN_Dodhia)\
**Post date:** [March 2, 2013, 6:34pm UTC](https://www.ruby-forum.com/t/help-radio-button/227061/1 "2013-03-02T18:34:40Z")

</div>

Hi i’m fairly new to ruby on rails and i’m creating a form using  
simple\_form and in one bit i have radio buttons and say i have 3 buttons  
a,b,c so i want it to be if a is pressed then certain text fields show,  
and  
if b is pressed a different set of text fields show and similarly for c.  
Can anyone help me on this?

---

<div class="post-metadata">

**Author:** ![NN\_Dodhia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@NN\_Dodhia](https://www.ruby-forum.com/u/NN_Dodhia)\
**Post date:** [March 2, 2013, 9:47pm UTC](https://www.ruby-forum.com/t/help-radio-button/227061/2 "2013-03-02T21:47:29Z")

</div>

On 2 March 2013 16:20, NN Dodhia [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hi i’m fairly new to ruby on rails and i’m creating a form using simple\_form  
> and in one bit i have radio buttons and say i have 3 buttons a,b,c so i want  
> it to be if a is pressed then certain text fields show, and if b is pressed  
> a different set of text fields show and similarly for c. Can anyone help me  
> on this?

You will probably want to use javascript for this, quite possibly  
jQuery. Have a look for some tutorials.

Colin

---

<div class="post-metadata">

**Author:** ![NN\_Dodhia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@NN\_Dodhia](https://www.ruby-forum.com/u/NN_Dodhia)\
**Post date:** [March 2, 2013, 11:19pm UTC](https://www.ruby-forum.com/t/help-radio-button/227061/3 "2013-03-02T23:19:11Z")

</div>

On Mar 2, 2013, at 11:20 AM, NN Dodhia wrote:

> Hi i’m fairly new to ruby on rails and i’m creating a form using simple\_form and  
> in one bit i have radio buttons and say i have 3 buttons a,b,c so i want it to be  
> if a is pressed then certain text fields show, and if b is pressed a different set  
> of text fields show and similarly for c. Can anyone help me on this?

This is a JavaScript thing, not really specific to Rails.  
Coincidentally, I just made this sort of behavior in a Drupal site this  
morning. For this form, there were fields that made sense for postal  
mail subscribers that did not make sense for email subscribers. So I  
added a classname to each of the field wrappers – either ‘postal’ or  
‘email’ and used that to make my behavior work:

> **[JSFiddle - React, Tailwind, and code Playground](https://jsfiddle.net/rk3vw/3/)**
>
> JSFiddle - Test your React, Tailwind, JavaScript, CSS, HTML online with JSFiddle.

This is using Prototype, I am sure you can use jQuery or “vanilla”  
JavaScript if that’s your thing.

Walter

---

<div class="post-metadata">

**Author:** ![NN\_Dodhia](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/c5a1d2/32.png) [@NN\_Dodhia](https://www.ruby-forum.com/u/NN_Dodhia)\
**Post date:** [March 3, 2013, 8:43am UTC](https://www.ruby-forum.com/t/help-radio-button/227061/4 "2013-03-03T08:43:31Z")

</div>

Maybe you can look at these screencasts and learn how to dynamically add  
form elements using javascript and then adapt it for your case as  
needed.

> **[\#196 Nested Model Form Part 1 - RailsCasts](http://railscasts.com/episodes/196-nested-model-form-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

> **[\#197 Nested Model Form Part 2 - RailsCasts](http://railscasts.com/episodes/197-nested-model-form-part-2)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

> **[\#196 Nested Model Form (revised) - RailsCasts](http://railscasts.com/episodes/196-nested-model-form-revised)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.
