I was tasked with having to create an unknown amount of textboxes dynamically with ColdFusion.
I was running into a lot of problems because something like this:
- <cfloop index="i" from="1" to="#numberoftextboxes#">
- <cfset myvar = FORM."txtbox_"&#i# />
- <cfoutput>
- #myvar#
- </cfoutput>
- </cfloop>
DOESN’T Work!
For this to work you need to use the EVALUATE function in ColdFusion. Create something like this:
- <cfloop index="i" from="1" to="#numberoftextboxes#">
- <cfset myvar = Evaluate( "FORM.txtbox_#i#" ) />
- <cfoutput>
- #myvar#
- </cfoutput>
- </cfloop>
If I have create 15 text boxes dynamically created, then submit the form, I can loop over all of them like I did above and it will give me the value of what was entered into each of the 15 text boxes.
Ben Nadel gives a little more detail with a few more examples about creating dynamic variables here:
http://www.bennadel.com/blog/152-Dynamic-ColdFusion-Variables-Via-Quoted-Naming.htm