• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

dynamic structure names in cfloop

New Here ,
Jul 08, 2006 Jul 08, 2006

Copy link to clipboard

Copied

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?
TOPICS
Advanced techniques

Views

557

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

New Here , Jul 08, 2006 Jul 08, 2006
The answer is evaluate()

<cfset loopCheckValue = " ">

<cfloop query=”rsReturnComputerSkills>
<cfset loopCheckValue = evaluate("structure.computerSkill" & "#currentRow#")>
<input type=”checkbox” #loopCheckValue# name=”computerSkill#currentRow#”>
</cfloop>

Votes

Translate

Translate
New Here ,
Jul 08, 2006 Jul 08, 2006

Copy link to clipboard

Copied

The answer is evaluate()

<cfset loopCheckValue = " ">

<cfloop query=”rsReturnComputerSkills>
<cfset loopCheckValue = evaluate("structure.computerSkill" & "#currentRow#")>
<input type=”checkbox” #loopCheckValue# name=”computerSkill#currentRow#”>
</cfloop>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2006 Jul 10, 2006

Copy link to clipboard

Copied

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>
>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 10, 2006 Jul 10, 2006

Copy link to clipboard

Copied

Ian is right. You want to avoid using evaluate() if possible. It's just not efficient.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2006 Jul 10, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 10, 2006 Jul 10, 2006

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 10, 2006 Jul 10, 2006

Copy link to clipboard

Copied

LATEST
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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation