Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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
Reply With Quote
  #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)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:48 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.