This can be done in straight Javascript.
You need two arrays (or a nice JSON oobject), a MAIN and a
SUB.
MAIN contains name, value pairs. SUB contains name, value
pairs AND
the member index from MAIN.
Call a function of the onchange event on the select
containing the
MAIN list.
In this function first clear the SUB select box
(document.forms['form1'].SUB.length=0) and loop through the
SUB array.
Where the main index value = the selected value from the
main
selection, add that item to the SUB select like so:
document.forms['form1'].SUB.options[document.forms['form1'].
SUB.length]
= new Option(name,val);
There might be an easier way to do this in Rails, but this
will work.
On Dec 31 2007, 11:23 am, Crispy <cris_palten... yahoo.com> wrote:
> Suppose you have two related drop downs (selects) that
you want to
> populate from a
> database. Assume one is Category, and the other is
Subcategory.
> When a Category is selected, you want the contents of
the
> Subcategory drop down to be populated with only those
Subcategories
> that are related to the Category selection.
>
> Another example might be a role based access framework
> and the first drop down is the controllers available
for a given
> right. Once the user selects a controller, you want
the next drop
> down populated with only the actions available for that
controller.
>
> Being a Rails Newbie, I wasn't sure I could tackle this
on my own, but
> it would be very useful.
> After reading about script.aculo.us, it sounded like
that might be in
> the right direction.
>
> Any suggestions on how to do this? Keep in mind, i'm
really new at
> this....
>
> Thank you!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs googlegroups.com
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe googlegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=
en
-~----------~----~----~----~------~----~------~--~---
|