Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to loop over Attributes?

Status
Not open for further replies.

philcha

Programmer
May 10, 2000
109
GB
I'm trying to build a dynamic form with several instances of:
Code:
<input type=&quot;text&quot; name=&quot;#variable_1#&quot; value=&quot;#variable_2&quot;>
where variable_1 consists of a prefix plus a code (e.g. product code).
I want to follow Fusebox in this app, so the first thing I do is converts all the URL and Form variables to Attributes. When processing this form, how can I find the names of the Attributes-scoped variables which contain the values? The Attributes' names will vary because the codes come from a database query, e.g. on one occurrence of the page they might be
Prod_45, Prod_78
and in another occcurrence they might be
Prod_34, Prod_85, Prod_102
If someone does answer this, can he/ she please state what versions of CF support the technique he / she recommends.
Thanks.
 
I normally recommend a different approach but since these come from a database query, I think a different approach is required.

When you generate the form, create a variable called &quot;varList&quot; and set it to &quot;&quot;. Each time you create a dynamic form variable, do a <cfset varList = listappend(varList,&quot;#variable_1#&quot;)>. This will create a comma delimited list of variable names. Then just pass this variable &quot;varList&quot; as a hidden form variable.

In the receiving script, you can loop through these like this:

<cfloop index=&quot;x&quot; list=#varList#>
<cfif isdefined(&quot;#x#&quot;)>
do whatever you want with it like <cfset myNewVar = evaluate(&quot;#x#&quot;)>
</cfif>
</cfloop>

This should work in CF 3.0 and up.

Hope this helps,
GJ
 
Thanks, GunJack! Your suggestion did the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top