How do I display dynamically named fields?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bushnellweb
    New Member
    • Jan 2010
    • 48

    How do I display dynamically named fields?

    In my form I named the check boxes "chk_img_" & #i#.
    So I get how to use it in IsDefined, but how do I get it to display the value of that FORM.check_img_ 1 without hard coding the number 1? Sometimes it might be like up to 1,000 and I'm not going to hard code a 1000000000 options. This is probabyl a very easy fix, but i've been up all night working on this code and now I'm dead in the water, with no brain power. Thanks in advance for the help.
    Code:
    <cfloop from="1" to="#intCheckBoxesCount#" index="i">
    <cfif IsDefined("FORM.chk_img_" & #i#)>
    <cfoutput>					chk_img_#i# value = #FORM.check_img_#<!--- this is where i am having trouble --->
    </cfoutput>
    </cfif>
    </cfloop>
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You can use the form struct (if using POST):
    Code:
    form["chk_img_" & #i#]

    Comment

    • bushnellweb
      New Member
      • Jan 2010
      • 48

      #3
      Originally posted by acoder
      You can use the form struct (if using POST):
      Code:
      form["chk_img_" & #i#]
      thanks, haha I've used it before. I don't know what I was/wasn't thinking

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Yes, it's easy to forget if not used often. Perhaps something to add to a "useful things easily forgotten" list :)

        Comment

        • iohos
          Banned
          New Member
          • Jul 2010
          • 45

          #5
          u cn cmbne text and vrble names to cnstrct a variable name on the left side of a cfset assgnmnt. e.g., d following code sets d value of d variable Product12 to the string "Widget":

          <cfset ProdNo = 12>

          <cfset "Product#ProdNo #" = "Widget">

          To cnstrct a vrble name dis way, all the text on the left side of the equal sign must be in quotation marks.

          dis usage is less efficient dan using arrays. The following example has the same purpose as the previous one, but requires less processing:

          <cfset MyArray=ArrayNe w(1)>

          <cfset prodNo = 12>
          <cfset myArray[prodNo] = "Widget">

          Comment

          Working...