• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

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"?
0
tauto
Asked:
tauto
  • 2
1 Solution
 
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">
  <label>
  <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>
    </cfoutput>
  </select>
  <input name="AlternateName" type="hidden" id="name" value="<cfoutput>#EmployeeRecordset.ALTERNATENAME#</cfoutput>" />
0
 
_agx_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#"
           type="hidden"
          id="name"
          value="#EmployeeRecordset.ALTERNATENAME#" />
</cfoutput>

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]>
     </cfif>
0
 
tautoAuthor Commented:
I ended up passing "employeeid" to another page and running a sepearte query to return "alternataname".  Thanks for the help!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now