Universal Related Popup Menus / Another Way | WebReference

Universal Related Popup Menus / Another Way

Another Way

Universal Related Popup Menus

Another way to approach the code is to first fill a two-dimensional array and create the new options on the fly. This technique makes it easier to add new menu items, and also extend this technique to another dimension. Here's a stripped down version for download.

Choose a subject:
---> Choose a topic:

Related Select Lists

Choose a subject:
---> Choose a topic:

The menus work identically to the previous page, and degrade gracefully. The array creation code has gone 2-D and now pregenerates the menu array outside the relate function.

Can You Relate?

The relate function, which changes the second menu based on the first menu's selection, has been stripped of the on the fly array creation and now uses the 2-D array we created above to change the second menu's options on the fly.

The guts of the relate function remain the same with two changes. The second menu's options array are now filled on the fly with the new Option command referring to the text and value properties of the a[j][i] element of our 2-D array. The aln2=a.length kludge was also replaced by calculating the length of the selectedIndex element of the 2-D array a (the number of options to be overwritten on the second menu).

This technique of pregenerating our options array can be extended into another dimension to create three related menus.

The full redirect.cgi script is also available in text form.

Comments are welcome

Created: Mar. 9, 1997
Revised: July 22, 1999

URL: http://webreference.com/dev/menus/intro2.html