Solved

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

Posted on 2004-08-05
2
273 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
hart earned 250 total points
ID: 11734044
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
ID: 11736335
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Help Fix A 403 error 13 121
DNS, website, godaddy 6 95
How code a 301 redirect for folder files -> 1 file 2 75
Soundcloud.com 4 86
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…
What You Need to Know when Searching for a Webhost Provider
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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