Solved

Pull down list based on the selection in another pull down list

Posted on 2004-08-05
2
241 Views
Last Modified: 2013-12-24
I have a database of different types of articles that I need to organize by different categories such as "Printing", "Troubleshooting", and "Policies".  In order to keep track of articles better there will also be sub categories for each different type.  For example, Troubleshooting will include subcategories of the diffent types of problems that need troubleshooted, while Policies will have a completely different list of subcats.

When writing articles the user will have the option of picking what category and subcategory there article belongs to.

Is there a way to make the pull down list of subcats change depending on what category is selected form another pull down list?  I am using Coldfusion 4.5.


this is a sample of the database i am using (as you can see subOf is a foriegn key for CATEGORIES and is used to show what subcat belongs to what cat):


CATEGORIES:

id          cat  
1           Printing
2           Troubleshooting
3           Polices



SUBCATS

id           subcat           subOf
1            HP 8150         1
2            HP 4050         1
3            Unix               2
4            Windows        2
5            Payroll           3
6            HR                 3
0
Comment
Question by:jasco4617
2 Comments
 
LVL 11

Accepted Solution

by:
hart earned 250 total points
Comment Utility
this can be done in many ways ....

Either using javascript arrays or by using cf tag...


But try this out first, its a tag that does what u want

http://www.geocities.com/thanny/CF_TwoSelectsRelated.zip

Regards
Hart
0
 
LVL 35

Expert Comment

by:mrichmon
Comment Utility
The two related selects tag is also available from Macromedia with a 3 related selectrs tag.

GO to
http://www.macromedia.com/cfusion/exchange/index.cfm
and hit --> search exchange
enter "related select" in the search box and choose "Cold Fusion Exchange" in the drop down

Then you will get the free download for both 2 related selects and 3 related selects

Or if you need more control over the data then you can write it yourself.  The following code fill sin the buyer list based off a the department selected.

<script type="text/javascript" language="JavaScript">
<!--
/* Dynamically populate Buyer select box based on seleted DepartmentID */
// Create an array to hold Buyers
var BuyerArray = new Array;

// Define a custom Javascript object type to represent a single Buyer
function Buyer(BuyerUsername, DepartmentID, BuyerName)
{
     this.BuyerUsername = BuyerUsername;
     this.DepartmentID = DepartmentID;
     this.BuyerName = BuyerName;
}
<!--- For each Buyer, append a new Buyer object to the array of Buyers --->
<cfoutput query="GetBuyers">
     BuyerArray[BuyerArray.length] = new Buyer("#JSStringFormat(Username)#", "#JSStringFormat(DepartmentID)#", "#JSStringFormat(BuyerName)#");
</cfoutput>

/* Fill the Buyer select box based on the DepartmentID */
function fillBuyers()
{
     // Stop if there is no selected ParentID
     if (document.AddIssue.DepartmentID.selectedIndex == -1)
     {
          return;
     }
     
     var DepartmentID = document.AddIssue.DepartmentID.options[document.AddIssue.DepartmentID.selectedIndex].value;
     
     // Remove all options in the Buyer select box
     document.AddIssue.Buyer.options.length = 0;
     
     // For each item in the Buyer array ...
     for (var i = 0; i < BuyerArray.length; i++)
     {
          // If the Buyer's DepartmentID is the same as the currently selected DepartmentID
          if (BuyerArray[i].DepartmentID == DepartmentID)
          {
               // Put a new option in the Buyer select box
               document.AddIssue.Buyer.options[document.AddIssue.Buyer.options.length] = new Option(BuyerArray[i].BuyerName, BuyerArray[i].BuyerUsername);
          }
     }
}
-->
</script>


<select name="DepartmentID" onChange="fillBuyers()" style="width: 200px;">
     <option value=""></option>
     <option value="GM">General Merchandise</option>
     <option value="TR">Trade</option>
     <option value="TX">Text</option>
</select>

<select name="Buyer" style="width: 200px;"></select>
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now