tigerpuzzle
tigerpuzzle

Reputation: 69

ColdFusion loop through Struct

I have these codes in Application.cfm:

<CFSET Application.Payroll.Garnishment.PmtCodes = structNew()>
<CFSET Application.Payroll.Garnishment.PmtCodes[1] = "0 - Canceled check">
<CFSET Application.Payroll.Garnishment.PmtCodes[2] = "1 - Closed paymentadjustment">
<CFSET Application.Payroll.Garnishment.PmtCodes[3] = "2 - Multiple payments on one check">
<CFSET Application.Payroll.Garnishment.PmtCodes[4] = "3 - ACH/CTP Payments">
<CFSET Application.Payroll.Garnishment.PmtCodes[5] = "5 - Check Pick-up">
<CFSET Application.Payroll.Garnishment.PmtCodes[6] = "5A - Special Handling">
<CFSET Application.Payroll.Garnishment.PmtCodes[7] = "7 - One invoice paid on one check">
<CFSET Application.Payroll.Garnishment.PmtCodes[8] = "8 - Payroll - Garnishment (Payroll use only)">
<CFSET Application.Payroll.Garnishment.PmtCodes[9] = "9 - Manual check/wire transfer/bankdraft">
<CFSET Application.Payroll.Garnishment.PmtCodes[10] = "C - ACH Transfers (ap use only)">
<CFSET Application.Payroll.Garnishment.PmtCodes[11] = "D - Foreign bank drafts">
<CFSET Application.Payroll.Garnishment.PmtCodes[12] = "H - Hospital Managed Care">
<CFSET Application.Payroll.Garnishment.PmtCodes[13] = "M - Cash advances (AP use only)">
<CFSET Application.Payroll.Garnishment.PmtCodes[14] = "T - Wire US/ Foreign $ to Foreign bank (ap)">
<CFSET Application.Payroll.Garnishment.PmtCodes[15] = "V - Multiple Vendor Payments on credit card">
<CFSET Application.Payroll.Garnishment.PmtCodes[16] = "W - Wire US/Foreign $ US/Foreign bank (ap)">
<CFSET Application.Payroll.Garnishment.PmtCodes[16] = "Y - Payroll rush Checks (ap use only)">
<CFSET Application.Payroll.Garnishment.PmtCodes[16] = "Z - Student Aid check from Banner">

I am trying to utilize the struct to create a drop down list on update-employee.cfm like so:

<SELECT NAME="PmtCodes" SIZE="1">    
    <CFOUTPUT>      
    <CFLOOP collection="#Application.Payroll.Garnishment.PmtCodes#" item="key">
       <OPTION VALUE="#Application.Payroll.Garnishment.PmtCodes[key]#">  </OPTION>       
    </CFLOOP>
    </CFOUTPUT>
</SELECT>

However, there is no data populated in the drop down list. Any suggestions? Thanks.

Upvotes: 1

Views: 813

Answers (2)

James A Mohler
James A Mohler

Reputation: 11120

You need to show something in the <option> tags

If you want to show the value and return the value

<OPTION VALUE="#Application.Payroll.Garnishment.PmtCodes[key]#">#xmlformat(Application.Payroll.Garnishment.PmtCodes[key])#</OPTION>

If you want to return the key

<OPTION VALUE="#key#">#xmlformat(Application.Payroll.Garnishment.PmtCodes[key])#</OPTION>

Include xmlformat() so that if your struct has special characters, it won't break the form

Upvotes: 2

Unknown Coder
Unknown Coder

Reputation: 6731

I think you need to include something within the OPTION tags too. So I would write that section as

<OPTION VALUE="#Application.Payroll.Garnishment.PmtCodes[key]#"> #Application.Payroll.Garnishment.PmtCodes[key]#  </OPTION> 

Upvotes: 0

Related Questions