Click to See Complete Forum and Search --> : Coldfusion form question - dynamic variable name


richiebaby321
03-11-2005, 09:43 AM
Hello,

This is a ColdFusion related question, I hope that you guys out there can help me.

Here is a line of html taken from my form;
<input type="radio" name="radioButton#Counter#" value="add">
<input type="radio" name="radioButton#Counter#" value="del">
As you can see I have a radio button that is dynamically named; radioButton1, radioButton2, radioButton3,... and so on. They are grouped together so you can only select one button to select the values 'add' or 'delete'

That part works fine, I hit problems when I am processing the form after the submit.

I can successfully read the selected value by using the following code (remember it's ColdFusion!);

<cfoutput>You selected the #radioButton1# column</cfoutput>
and I receive "You selected the del column"

I would like to refer to the radio button dynamically because there are about 15 of them in a list, each allowing a delete or add for different items. But when I try the following, I receive a "Page cannot be displayed" error.

Idea 1) <cfoutput>You selected the #radioButton(var)# col</cfoutput>
Idea 2) <cfoutput>You selected the #radioButton[var]# col</cfoutput>
Idea 3) <cfoutput>You selected the #radioButton##var# col</cfoutput>

I'm sure that I've tried other variations but nothing seems to work when I replace the value with a variable.

Any ideas?

Rich.

richiebaby321
03-11-2005, 12:26 PM
I used the code below to check the values of the selected radio buttons and place them into an array.

<cfset i = 1>

<cfloop index="Counter" from="#min#" to="#max#">
<cfif IsDefined("form.radioButton#Counter#")>
<cfset id=#Evaluate("#Counter#")#>
<cfif #Evaluate("radioButton"&"#id#")# is "add">
<cfoutput>Add</cfoutput><br>
<cfset Array[#i#][1]=#Counter#>
<cfset Array[#i#][2]='add'>
<cfset i = i + 1>
<cfelse>
<cfoutput>Del</cfoutput><br>
<cfset Array[#i#][1]=#Counter#>
<cfset Array[#i#][2]='del'>
<cfset i = i + 1>
</cfif>
</cfif>
</cfloop>

Ideas found at:
http://www.sys-con.com/story/?storyid=42027&DE=1