Returning multiple columns from dynamic drop list

Posted on 2007-10-17
Last Modified: 2013-12-24
I've created a form using Dreamweaver CS3 and Coldfusion MX6.  I have a dynamic drop down list that displays "Employee Name" but returns the vaule "Employee ID".  What is the easiest way to capture another column in the selected recordset e.g. "Employee Alternate Name"?
Question by:tauto

    Author Comment

    More info...I'm populating the drop down list by calling a stored procedure.  The stored procedure returns the following columns: EmployeeName, EmployeeID, AlternateName.  As stated previously, I'm using EmployeeName as the display name and EmployeeID as the value.  I need to capture the AlternateName value also.  Here's the code.  I'm passing EmployeeID and Alternatename as form variables.  EmployeeID is correct but Alternatename is always the first in the recordset.

    <form id="form" name="form" method="post" action="test_output.cfm">
      <span class="style1">Employee Name:</span>
      <select name="Employee" id="Employee">
        <option value="null"></option><cfoutput query="EmployeeRecordSet">
          <option value="#EmployeeRecordSet.EMPLOYID#">#EmployeeRecordSet.EMPLOYEE_NAME#</option>
      <input name="AlternateName" type="hidden" id="name" value="<cfoutput>#EmployeeRecordset.ALTERNATENAME#</cfoutput>" />
    LVL 51

    Accepted Solution

    > EmployeeID is correct but Alternatename is always the first in the recordset.
    > value="<cfoutput>#EmployeeRecordset.ALTERNATENAME#</cfoutput>" />

    That's because you're not looping through the query. #queryName.columnName# will always points to the first row in the query unless its inside a <cfoutput query=".."> or <cfloop query=".."> .

    You could run a separate query on your action page to lookup the alternate name using the #form.Employee# id.  

    Another option is loop through the query and generate dynamically named fields. Not tested, but something like this

    <cfoutput query="EmployeeRecordset">
    <input name="AlternateName#EmployeeRecordSet.EMPLOYID#"
              value="#EmployeeRecordset.ALTERNATENAME#" />

    Then retrieve the value on the action page:

         <!--- default if nothing was selected --->
        <cfparam name="form.Employee" default="null">
         <!--- use the selected employee id to get the alternate name value --->
         <cfif form.Employee is not "null" and IsDefined("form.AlternateName#form.Employee#")>
               <cfset selectedAlternateName = form["form.AlternateName"& form.Employee]>

    Author Comment

    I ended up passing "employeeid" to another page and running a sepearte query to return "alternataname".  Thanks for the help!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Javascript: Crash Course

    Javascript is not only emerging as the most important language to know, it's flexibility is unique. With Javascript being deployed on the web, mobile and even the desktop this is the one language that all technologists need to know.

    Suggested Solutions

    This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
    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 …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 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

    10 Experts available now in Live!

    Get 1:1 Help Now