How to concatenate two lines and use the result as a variable name in coldfusion?

I have a form that has many fields in the format

  • name = "field-1"
  • name = "field-2"
  • name = "field-3"
  • name = "Field-4"
  • etc....

On the form's action page, I would like to be able to use the loop and be able to use the loop index for concat with a line prefix like this <cfset newField = "field-" & #index#>, and then use #Variables.newField#to access the form field on the previous page.

I played with the function Evaluate(), but no luck. I don't use ColdFusion very often, so I can just sit a bit in the syntax.

An example of how I use it:

<cfset newField = "form.field-" & #index#>
<input type="hidden" 
      name="field-<cfoutput>#index#</cfoutput>" 
      value="<cfoutput>Evaluate(Variables.newField)</cfoutput>">
+5
source share
2

. struct .

<cfset newField = "form.field-" & index>
<cfset value = variables[newField]>

<cfset value = variables["form.field-#index#"]>

<cfoutput>#variables["form.field-" & index]#</cfoutput>
+8

variables. , form, :

<input type="hidden" name="field-<cfoutput>#index#</cfoutput>" 
value="<cfoutput>#form['field-' & index]#</cfoutput>">

, :

<cfif structKeyExists(form, 'field-' & index)>
    <!--- display field --->
</cfif>
+4

All Articles