Skip to main content
Inspiring
July 29, 2009
Answered

Looping dynamic variables

  • July 29, 2009
  • 3 replies
  • 811 views

Hi

I have the following...

<Cfloop from 1 to 100 index i>

<cfif isDefined ('FORM.JACKET#i#')>
    <cfset jacketsize = #FORM.JACKET#i##>
</cfif>

</cfloop>

I need to know how to get the correct value from #FORM.JACKET#i##

Can anybody assist?

thank you

Delon

This topic has been closed for replies.
Correct answer Dan_Bracuk

form["jacket" & i]

3 replies

Inspiring
July 30, 2009

In the context of an HTML incoming data-stream (i.e. FORM), the data will always be "flat."  Therefore, repeating values must be given unique names such as "JACKET18," which you do when building your code.  It is perfectly acceptable thereafter to loop through "all possible values," checking that each one does or doesn't exist, as has been shown.  Browsers vary in their handling of empty-fields:  some browsers include them in the stream while others do not.

Outside of the context of an HTML data-stream, though, in the general sense any element of a Struct may be any sort of complex data-type you care to invent... array, another structure... or a simple data-value such as the numeral "2."  myStruct.jacket could be an array of "jacket description" structures, each one containing who-knows-what.

Inspiring
July 29, 2009

short and sweet!

thank you.

Dan_BracukCorrect answer
Inspiring
July 29, 2009

form["jacket" & i]