By: jhi
Description Of Problem

I help with creating web applications for a medical school. They were interested in creating forms in which the user could select information then be able to come back to that information with their information already in place. The only problem was that they needed a menu to select which hospitals the residents were in. The other problem was that they also wanted a drop down menu.

This tutorial is broken down into:

General Overview
Code (with Comments)

General Overview:

It is a dynamic menu tested and run on a Coldfusion MX Server Platform. I have not tested it with other versions of Coldfusion yet. It is generated via a list of hospitals and clinics and a session variable.

(Side Note)
Instead of a session variable originally it was a SQL query. I decided that passing session variables around with the information I can reuse the form. First when the form is first entered the variables are blank. Then when people come back they type in their identification and the values are retrieved from the SQL database.

I decided to utilize Coldfusion’s list functionality. So instead of doing multiple options within a select I decided that I would output the list of hospitals in my list. The nice part about this is that one can easily modify the list by simply either moving or deleting the hospitals and or clinics.

I apologize if this tutorial was already posted I have searched easycfm.com numerous times to find this type of menu maker but was unable. I hope this is a help to someone.

Code:

Sample hospital/clinic list:

<cfset hospitalClinicList=
"HospitalName1;
HospitalName2;
HospitalName3;
HospitalName4;
HospitalName5;
ClinicName1;
ClinicName2;
ClinicName3;
ClinicName4;
ClinicName5;"
>

Multiple Selection Menu:

<select name="hospitalClinic" size="5" multiple>

    <cfset globalHospitalClinic="">
    <!--We set a globalHospitalClinic variable in order to check whether or not we have already highlighted it in our menu.-->

    <cfloop list="#hospitalClinicList#" index="hospitalClinic" delimiters=";">
        <!—We loop through our list and specify which delimiters we are using to separate our the names of our hospitals and clinics.-->

        <cfloop list="#session.residents.hospitalClinic#" index="myHospitalClinic">
            <!—We pass what clinics we have selected as a variable --->

            <cfif trim(hospitalClinic) is trim(myHospitalClinic)>
            <!—We check to see if the hospital and or clinic matches the one in the list. If it does we select it and set the globalHospitalVariable to identify that in fact we have already selected the hospital.-->

                <option value="#hospitalClinic#" selected>#hospitalClinic#</option>
                <cfset globalHospitalClinic=hospitalClinic>
            </cfif>
        </cfloop>

        <cfif trim(hospitalClinic) is not trim(globalHospitalClinic)>
            <!—We check to make sure that we have not already selected the hospital and or clinic.-->
            <option value="#hospitalClinic#">#hospitalClinic#</option>
            <!—If we have not then we display it.-->
        </cfif>

    </cfloop>
</select>

Dynamic Drop Down Menus:

Again by utilizing session variables as well as lists we can create a dynamic drop down menu.

<select name="yearInResidency">

    <option value="">Select</option>

    <cfloop list="#yearInResidencyList#" index="yearInResidency" delimiters=";">
        <!—We loop through what year they are in their residency.-->

        <cfif trim(yearInResidency) is trim(session.residents.yearInResidency)>
            <!—We then compare the session variable with the piece of the list we are currently looking at --->

            <option value="#yearInResidency#" selected>#yearInResidency#</option>
            <!—If this is true we select it --->
        <cfelse>
            <option value="#yearInResidency#">#yearInResidency#</option>
            <!—If not we do not select it and simply display it--->
        </cfif>

    </cfloop>

</select>

About This Tutorial
Author: jhi
Skill Level: Intermediate 
 
 
 
Platforms Tested: CFMX
Total Views: 22,128
Submission Date: February 04, 2005
Last Update Date: June 05, 2009
All Tutorials By This Autor: 1
Discuss This Tutorial
  • Very cool stuff... I'm wondering if it will be a little obsolete after Colfusion 8 with the cfMenu tags...

Advertisement

Sponsored By...
Powered By...