Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 25th, 2008, 05:50 AM
Authorized User
 
Join Date: Jan 2008
Location: , , .
Posts: 46
Thanks: 0
Thanked 0 Times in 0 Posts
Default Drop down

Hello

How can I create a Javascript drop down list File? I want to have a webpage that contain a dropdownlist. But i want the items and values of that drop down lists to be stored in a seperate javascript file, So that my webpage call that JS file whenever user click on the DDList.

Basically what i am interested in is to place all my drop down list Items manually in the javascripting file and then on the main page there will be links from alphabet A-Z so when the user click on alphabet A the dropdown list will only show the containing items start with alphabet A....


Hope this makes sense!! The reason why is because there is a long list of items and i dont want to put them inside my page.

Will be really appreciated if someone reply with code.......

Many Thanks



Regards

Sheraz
  #2 (permalink)  
Old January 25th, 2008, 07:46 AM
joefawcett's Avatar
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)


Similar Threads
Thread Thread Starter Forum Replies Last Post
drop down p2pMember ASP.NET 1.0 and 1.1 Basics 1 February 20th, 2006 06:34 AM
drop down list values based on another drop down noor ASP.NET 1.0 and 1.1 Basics 3 July 5th, 2005 09:57 AM
value of the drop-down crmpicco Classic ASP Basics 15 February 24th, 2005 11:11 AM
Drop down sinner Classic ASP Databases 2 March 19th, 2004 02:51 PM
Populating Drop Down based on other drop down jeffbarclay Java Databases 1 November 7th, 2003 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.