Returning multiple columns from dynamic drop list

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"?
Who is Participating?
_agx_Connect With a Mentor Commented:
> 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]>
tautoAuthor Commented:
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>" />
tautoAuthor Commented:
I ended up passing "employeeid" to another page and running a sepearte query to return "alternataname".  Thanks for the help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.