Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-08-05
2
Medium Priority
?
290 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 1000 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

Simplify Your Workload with One Tool

How do you combat today’s intelligent hacker while managing multiple domains and platforms? By simplifying your workload with one tool. With Lunarpages hosting through Plesk Onyx, you can:

Automate SSL generation and installation with two clicks
Experience total server control

Question has a verified solution.

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

Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
When it comes to showing a 404 error page to your visitors, you do not want that generic page to show, and you especially do not want your hosting provider’s ad error page to show either. In this article, I will show you how to enable the custom 40…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

636 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