xSelect is another experiment in unobtrusive DHTML.
xSelect implements categories and sub-categories as two SELECT controls where the contents of the second control dynamically change depending on the selection in the main control.
xSelect is part of the X Library from Cross-Browser.com and is licensed LGPL.
View the source and documentation for xSelect.
In your HTML create a SELECT element (let's call it s0) which contains OPTGROUP elements. Within each OPTGROUP can be any number of OPTION elements. Given the id of s0, xSelect creates two SELECT elements:
s1 and s2 are dynamically created and appended to the same form which contains s0. s0 is hidden, s1 is positioned where s0 was, and s2 is positioned under or to the right of s1.
If the browser doesn't support the objects required by xSelect, or if the user has Javascript disabled, then xSelect will downgrade (do nothing) and the user will get the original SELECT which contains all main categories (as OPTGROUPs) and all sub-categories (as OPTIONs within each OPTGROUP).
If javascript is enabled and the browser supports the required objects, the user will get the following.
The following SELECT is what the above would look like in 'downgrade' mode.
Here's another example, to show that multiple xSelect objects can be instantiated on the same page.
The following SELECT is what the above would look like in 'downgrade' mode.
Cross-Browser.com is the home of X - a cross-browser Javascript library, and many demos, applications, articles and documentation.
By your use of X and/or CBE and/or any Javascript from this site you consent to the GNU LGPL - please read it. If you have any questions about the license, read the FAQ and/or come to the forums.
Forum support is available at the X Library Support Forums.