Solved

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

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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

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…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

690 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