Chained Selects Examples: Share a list group with different pages
Sometimes we want to re-use the same list group content in different pages and each page can have its own default options.
For example, we have the following list content and list group:
There is no default options defined in the list group.
Let's say we save this list group as "content.js" and we want to pick [ Honda ] >> [ SUVs/Van ] >> [ Odyssey ] as the default options for a page. We can then set up the page like this:
In this example, the selectOptions() call first looks for an option with "Honda" as the display text in the top-list of "vehicles" list group, make it a default option, then looks for "SUVs/Van" in the sub-list of "Honda", make it default and looks for "Odyssey" in the sub-list of "SUVs/Van" and make it default.
The selectOptions() call let us "travel" down the list group and make the options we "pass by" as default options. Chances are we might not want to set each option we "pass by" as default option. For example, we might only want to set the "SUVs/Van" >> "Odyssey" as default options for "Honda" when it's picked from the top-list but not "Honda" itself as a default option in the top-list. To do so, we can call the selectOptions() like this:
selectOptions("vehicles", "Honda:-:SUVs/Van::Odyssey", 0);
Click [ here ] to see the demo page.
Note: The selectOptions() call actually overwrites the default parameters defined in addList() and addOption() calls.
Note: The last parameter in the selectOptions() call could be: 0 (the option text is compared to the given option "path"), 1 (the optinon value is compared) or 2 (the option index is compared).
# # #