JIMMY
JIMMY

Reputation: 37

Accessing data in a loop of text field with ColdFusion

I am fairly new to ColdFusion, and don't quite understand how variable access works. I've created a table that generates a number of text fields named condesc#i#, where i is the current index in a cfloop.

I then have a second loop, that attempts to access the contents of each field that has been created. I have attempted to make access using #condesc#i##, but with no success.

How should I go about getting the information from these fields?

Upvotes: 2

Views: 362

Answers (2)

Sam Farmer
Sam Farmer

Reputation: 4118

All variables are structures so you can access them like this:

form[ "condesc" & i ]

And dynamically build the keys.

Upvotes: 5

Ben Doom
Ben Doom

Reputation: 7885

You can reference dynamic variable names by using bracket notation and string concatenation:

<cfloop from="1" to="#count#" index="i">
    #form['condesc' & i]#  <br />
</cfloop>

Upvotes: 4

Related Questions