views:

33

answers:

0

Hi,

I was wondering if there is a way to use radio button to set the value of a field that is a text box.

    <%= radio_button("demographics_questionaires", "gender", "Male")%> Male <br\>
    <%= radio_button("demographics_questionaires", "gender", "Female")%> Female <<br\>
    <%= radio_button("demographics_questionaires", "gender", "Other")%> 
    Other <%= f.text_field gender %> 

Above code is incorrect, but something on that lines.

If the other radio button is selected, I want gender to be set to the value of the text_field? Not sure how you do that association?

Ex.

[radio button] Male

[radio button] Female

[radio button] Other ________

where ____ is the text box to enter.

In the end If the user choose male, I want the value the is stored in the database to be "Male", for female "FEMALE", or for other what the user inputs.

I kind of wanted to handle all the logic in the view. Is that possible or does it have to be done in the controller?

Any advice appreciated,