Some Tags Never Get Old
You heard me right I said tags not things. That is because today I came across another situation where a very popular custom tag was the right solution. If you have been developing for any amounts of time I am sure you have come across the related selects problem. What is that you ask? Two related selects is where the second select box is populated based on the users selection from the first. So how do you go about this without tricky Javascript? That is the easy part. A custom tag that has stood the test of time is Nate Weiss CF_TwoSelectsRelated, V1.0 custom tag still works like a charm. I have a list of most of the major colleges / universities in the United States and based on what state the user selects the second drop down will be populated with Colleges from that state.
The first thing you need to do is download the custom tag and you can it right from Adobe exchange. Unfortunately I have not found an easy way to link directly to the tag so you will need to search the exchange for two selects related. Once you have it downloaded place it right in the project directory or any directory in your custom tags path. The first code I need to get is a list of colleges. This query is basically going to be the college id, the name, and the state, the query will be ordered by the state. Here is my query.
<cfset var listColleges = "">
<cfquery name="listColleges" datasource="#variables.dsn#">
SELECT collegeId, name, state
FROM college
ORDER BY state,name
</cfquery>
<cfreturn listColleges>
</cffunction>
QUERY="colleges"
NAME1="state"
NAME2="college"
DISPLAY1="state"
DISPLAY2="name"
VALUE1="state"
VALUE2="collegeId"
EMPTYTEXT1="(choose a state)"
EMPTYTEXT2="(now choose a college)"
AUTOSELECTFIRST="No">
