# Conditional form element

**URL:** <https://www.ruby-forum.com/t/conditional-form-element/67735>\
**Category:** Rails\
**Created:** [September 6, 2006, 1:09pm UTC](https://www.ruby-forum.com/t/conditional-form-element/67735 "2006-09-06T13:09:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [September 6, 2006, 1:09pm UTC](https://www.ruby-forum.com/t/conditional-form-element/67735/1 "2006-09-06T13:09:45Z")

</div>

I have a button option in my form with 2 options. User may only select  
one of the options. Based on the option they choose I want an  
associated select list to appear. I’m guessing this can only be done  
with javascript or can it be done with just Ruby ?

TIA  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [September 6, 2006, 4:58pm UTC](https://www.ruby-forum.com/t/conditional-form-element/67735/2 "2006-09-06T16:58:15Z")

</div>

In case this wasn’t clear I wanted to elaborate a little more.  
The user would choose from either an “annual” or “hourly” option.  
Based on that there would be a list listing dollar amounts. When I  
first built the amounts table there was a secondary id column , where  
id-1 was annual and id-2 was hourly.  
Anyway, I guess this is a javascript thing but then would the whole  
template need to be a rjs ?  
Also if there are any pure Ruby options to accomplish this , that  
would be better.

TIA  
Stuart

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [September 6, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/conditional-form-element/67735/3 "2006-09-06T17:24:18Z")

</div>

Why not use Ajax? You could use form\_remote\_tag to make the annual and  
hourly buttons into forms (independent of your main form) (iirc you  
can’t nest forms).

You could then wrap the dollar-amount-selector (and a hidden  
annual-or-hourly text field, if needed) in a div and have the contents  
of that div replaced by the server whenever the annual or hourly  
buttons were clicked.

(Yes it is all javascript behind the scenes, but javascript which has  
already been written.)

Hope it helps,

Regards

Chris.

---

<div class="post-metadata">

**Author:** ![zanoni](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/e99b99/32.png) [@zanoni](https://www.ruby-forum.com/u/zanoni)\
**Post date:** [September 6, 2006, 6:12pm UTC](https://www.ruby-forum.com/t/conditional-form-element/67735/4 "2006-09-06T18:12:28Z")

</div>

On 9/6/06, Chris D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Why not use Ajax? You could use form\_remote\_tag to make the annual and  
> hourly buttons into forms (independent of your main form) (iirc you  
> can’t nest forms).

I don’t believe there is a reason couldn’t nest forms.

> You could then wrap the dollar-amount-selector (and a hidden  
> annual-or-hourly text field, if needed) in a div and have the contents  
> of that div replaced by the server whenever the annual or hourly  
> buttons were clicked.

This would still show up within the main form ? And do I move  
everything to a RJS template ?

Stuart
