3 Replies Latest reply on Jul 30, 2009 8:04 AM by TLC-IT

    Looping dynamic variables

    Flashdakota

      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

        • 1. Re: Looping dynamic variables
          Dan Bracuk Level 5

          form["jacket" & i]

          • 2. Re: Looping dynamic variables
            Flashdakota Level 1

            short and sweet!

            thank you.

            • 3. Re: Looping dynamic variables
              TLC-IT Level 3

              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.