Form magic

Didn’t know what else to call this subject, sorry.
Anyway this is more a general discovery question then a coding one.

Is it possible (and I already know it should be) to create forms where
depending on a particular choice in one select tag, one or another
select tags would be presented in the form.

As an example, a shopping site , where a dropdown has options of:
1-Men’s shoes
2-Women’s shoes
3-Children’s shoes

If user selects Men’s shoes, then the following form field / select
would present a set of options for men’s shoes, etc. Similarly, the
other options would generate other select options particular to those
groups (women’s or children’s).

So, while I know this is doable, is it something that requires Ajax or
JS or more native types of calls with Ruby ?

Hope this is a reasonable question.

TIA
Stuart

Here’s something I use for presenting a list of countries to the user
and then having a different set of localities (provinces/states/etc)
display depending upon their country choice. This uses a javascript
onchange method with an ajax callback to update the element with the
“locality” id, and in my :change_country action, I render a different
partial template depending upon the user_country parameter. You
should be able to adapt this for what you want to do.

  <select id="user_country_id" name="user[country_id]"

onchange="<%= remote_function( :update => ‘locality’, :url => {
:action => :change_country }, :with => “‘user_country=’ +
$F(‘user_country_id’)”) %>">

Mike

thanks Mike, it will probably be a few days at least till I can try it
out but it sounds and looks good. Appreciate the code example!

Stuart

Hey Stuart,

Just this morning I found the following link for creating chained select
boxes using PHP and AJAX:

This might be useful to you. The example uses a static PHP file with the
options, but should be easy to convert to a database driven select
boxes.

Neil.

Neil,

Thanks for the link. I currently have some php “stuff” but prefer to
keep Ruby-centric. Still good to know about what’s out there. Much
appreciated.

Stuart