6 Replies Latest reply on Jul 10, 2006 11:24 AM by Newsgroup_User

    dynamic structure names in cfloop

    FattMatt
      I have designed a web application that allows users to enter a number of records on one form – for example computer skills. The user can add up to 20 different computer skills.

      On another form, the user’s recorded computer skills are shown as a number of dynamic checkboxes. One computer skill means the user sees one checkbox. Twenty computer skills means the user sees 20 checkboxes. I have made a query loop to output these computer skills and checkboxes. I have also made structure variables so that the selection of the specific computer skill checkbox is retained for later use in the web application. If the user checks any of the checkboxes, on submission of the form, the structure value is updated from no to yes (and vice versa). This part is working, and I am happy with it.

      The problem I have is that I am unable to find a way to individually indicate that the specific checkbox value is checked or not. If the user selects the checkbox, submits the form and returns to the form, the checkbox should still show as ticked as the structure value of that checkbox is “yes” (as in checked=”yes”). As I am using structures, adding #currentRow# to the structure name inside the loop does not work, as CF views this as a different structure name that is not recognised. For example:

      <cfloop query=”rsReturnComputerSkills

      <cfinput type=”checkbox” name=”computerSkill#currentRow#” checked=”#structure.computerSkill##currentRow#”

      </cfloop>

      Essentially, I cannot place the dynamic structure value into the checkbox input field.

      I thought that using an array may overcome this, but alas I encounter the same problem.

      Is there a way to append #currentRow# to the structure name or is there another way to achieve the same that I have not thought of?
        • 1. Re: dynamic structure names in cfloop
          FattMatt Level 1
          The answer is evaluate()

          <cfset loopCheckValue = " ">

          <cfloop query=”rsReturnComputerSkills>
          <cfset loopCheckValue = evaluate("structure.computerSkill" & "#currentRow#")>
          <input type=”checkbox” #loopCheckValue# name=”computerSkill#currentRow#”>
          </cfloop>
          • 2. Re: dynamic structure names in cfloop
            Level 7
            A better answer is the [] notation for arrays and structures.

            <cfset loopCheckValue = structure['computerSkill' & currentRow]>

            FattMatt wrote:
            > The answer is evaluate()
            >
            > <cfset loopCheckValue = " ">
            >
            > <cfloop query=?rsReturnComputerSkills>
            > <cfset loopCheckValue = evaluate("structure.computerSkill" & "#currentRow#")>
            > <input type=?checkbox? #loopCheckValue# name=?computerSkill#currentRow#?>
            > </cfloop>
            >
            • 3. Re: dynamic structure names in cfloop
              Kevin Schmidt Level 1
              Ian is right. You want to avoid using evaluate() if possible. It's just not efficient.
              • 4. Re: dynamic structure names in cfloop
                Level 7
                There has been some evidence that this may not be as true in the current
                MX days then it was in CF 5 and before.

                But I find the bracket[] notion cleaner and one can certainly do more
                with it then one can easily do with evaluate() function(s).

                Kevin Schmidt wrote:
                > Ian is right. You want to avoid using evaluate() if possible. It's just not efficient.
                • 5. Re: dynamic structure names in cfloop
                  Kevin Schmidt Level 1
                  Interesting. Do you have the info on that Ian. As far as I know, at least in the latest Advanced CF Course, Adobe/MM was still saying that evaluate() brought with it a performance degradation.
                  • 6. Re: dynamic structure names in cfloop
                    Level 7
                    Just list server gossip (so take with a large grain of salt). But some
                    well regarded members have done simple timing tests and taken a look at
                    the Java byte code generated. Evaluate() seems to be pretty trim in the
                    latest versions of CFMX.

                    But I still try to avoid it, because while it may or may not slow down
                    execution, it definitely can slow down development if you do anything
                    more complicated then concatenate a simple string and a variable.

                    Kevin Schmidt wrote:
                    > Interesting. Do you have the info on that Ian. As far as I know, at least in the latest Advanced CF Course, Adobe/MM was still saying that evaluate() brought with it a performance degradation.