Thread: Drop down
View Single Post
  #2 (permalink)  
Old January 25th, 2008, 07:46 AM
joefawcett's Avatar
joefawcett joefawcett is offline
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

If I've understood your problem then I would approach it this way. I'd create a variable, in a separate js file if you wish, that looks something like:
Code:
var DDLOptions = {
a: [{value: "option 1 value", text: "option 1 text"},
    {value: "option 2 value", text: "option 2 text"},
    {value: "option 3 value", text: "option 3 text"}],
b: [{value: "option 1 value", text: "option 1 text"},
    {value: "option 2 value", text: "option 2 text"},
    {value: "option 3 value", text: "option 3 text"}],
//....
z: [{value: "option 1 value", text: "option 1 text"},
    {value: "option 2 value", text: "option 2 text"},
    {value: "option 3 value", text: "option 3 text"}]
}
You can the access the options for a particular letter via:
Code:
var oOptions = DDLOptions.a
//or
var oOptions = DDLOptions[a]
which gives an array of option data.

You then iterate through this array and create an option for each element using
Code:
oOptions[i].value and oOptions[i].text
where i represents the index of the current option. These are added to the empty select element that resides on the page.

Alternatively you could do this sort of processing server-side, it depends on how your web application works.

--

Joe (Microsoft MVP - XML)
Reply With Quote