Solved

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

Posted on 2004-08-05
2
253 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
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
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 …
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

920 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

12 Experts available now in Live!

Get 1:1 Help Now