You're trouble is you're not using the evaluate() function (and you're
using # gratuitously :).
<cfset varname = evaluate("form.id" & x)>
This will now be the value of from.id1 instead of the string "form.id1"
(through whatever). There are other ways to handle this as well.
One thing of note is instead of using the for style cfloop, use a while
(conditional) loop and you won't have to pass the number along, just add a
counter.
<cfset x = 1>
<cfloop condition="isDefined('form.id' & x)">
<cfset varname = evaluate("form.id" & x)>
<cfif varname is "Custom">
<!--- do this if custom --->
<cfelse>
<!--- do this if NOT --->
</cfif>
<cfset x = x + 1>
</cfloop>
This will now run from x to the first break in the ints up from it; so 1
until whatever you decide w/o you having to pass a number.
Alternately, if it's all logic you might want to use cfscript.
<cfscript>
x = 1;
while (isDefined("form.id" & x)) {
field = evaluate("form.id" & x) ;
if (field eq "Custom") {
// do this is custom
} else {
// do this if not
}
x = x + 1 ;
}
<cfscript>
-----Original Message-----
From: Martin S [mailto:[EMAIL PROTECTED]]
Sent: January 16, 2001 21:22
To: CF-Talk
Subject: Dynamic Variable Names
Hi,
In this example I have two pages...with a form post inbetween.
The first page has a lot of text boxes called ID1 to ID16 (so, 16 in total
;) ).....these boxes are in a database loop (thus the number to
differentiate them). Also over time the number may change from 16 to 18
etc..so there may be more text boxes.
I also pass this total number (16) to the second page in a hidden field.
On the second page I want to evaluate the value for each one..but as the
total number is not a constant I need to do a loop.
The following code is what I have come up with :
<cfoutput>
<cfloop from="1" to="#Form.TotalEvents#" index="i">
#I#
<cfset varname ="Form.ID#i#">
<cfif #varname# eq "Custom">#varname# = Custom</cfif><br>
</cfloop>
</cfoutput>
......end code.
What this is SUPPOSED to be doing is checking if the passed VALUE for
Form.ID1 (through 16) equals "Custom", and if so it does something, else
something else...
.....but what it is doing is a literal comparison, so there are NEVER any
true
results to the if statement, when infact with my current code 11 out of 12
should return true.
Can someone help me with this...it may be trivial to some of you..but I need
to get around this ASAP.
Thanks heaps!!!
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists