makila
asked on
ColdFusion - How do I output dynamic form variables?
I have a form where I loop through a query to list all users that are labeled managers in a database. Each manager then has an input box where I can enter a number to increase their balance. I cannot figure out how to output the number I enter into the input box. I did not hard code each managers name because the number of managers is always changing.
Basically, each manager's variable name is their NT login with "_ADD" after it (i.e. JDoe_ADD) and that variable would equal a whole number. I tried to use <cfoutput>#<cfoutput>#qryA M_Balances .NT_ID#</c foutput>_A DD#</cfout put> but it came back with an error. I tried <cfoutput>##<cfoutput>#qry AM_Balance s.NT_ID#</ cfoutput>_ ADD##</cfo utput> but then it just listed the variable name instead of the value.
Here is the code:
<FORM action="jackbucks_balances _II.cfm" method="post">
<table width="600" border="0" cellspacing="0" cellpadding="1">
<tr align="left" valign="top" bgcolor="#FFCC00" class="tinywhite">
<td width="200" class="small">
<b>user</b>
</td>
<td align="center" width="200" class="small">
<b>current balance</b>
</td>
<td align="center" width="200" class="small">
<b>add to balance</b>
</td>
</tr>
<cfloop query="qryAM_Balances">
<cfif intBgColor is 0>
<cfset intBgColor = 1>
<cfset strbgcolor = "##FFFFFF">
<cfelse>
<cfset intBgColor = 0>
<cfset strBgColor = "##E5E5E5">
</cfif>
<tr align="left" valign="center" bgcolor="<cfoutput>#strBgC olor#</cfo utput>" class="tiny">
<td>
<cfoutput>#lcase(qryAM_Bal ances.Rep_ Name)#</cf output>
</td>
<td align="center">
<cfoutput>#lcase(qryAM_Bal ances.Curr ent_Balanc e)#</cfout put>
</td>
<td align="center">
<input type="text" name="<cfoutput>#qryAM_Bal ances.NT_I D#</cfoutp ut>_ADD" value="0" size="3">
</td>
</tr>
</cfloop>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="1">
<tr align="right">
<td align="right">
<INPUT type="submit" value="add"> <INPUT type="reset" value="clear">
</td>
</tr>
</table>
</FORM>
Basically, each manager's variable name is their NT login with "_ADD" after it (i.e. JDoe_ADD) and that variable would equal a whole number. I tried to use <cfoutput>#<cfoutput>#qryA
Here is the code:
<FORM action="jackbucks_balances
<table width="600" border="0" cellspacing="0" cellpadding="1">
<tr align="left" valign="top" bgcolor="#FFCC00" class="tinywhite">
<td width="200" class="small">
<b>user</b>
</td>
<td align="center" width="200" class="small">
<b>current balance</b>
</td>
<td align="center" width="200" class="small">
<b>add to balance</b>
</td>
</tr>
<cfloop query="qryAM_Balances">
<cfif intBgColor is 0>
<cfset intBgColor = 1>
<cfset strbgcolor = "##FFFFFF">
<cfelse>
<cfset intBgColor = 0>
<cfset strBgColor = "##E5E5E5">
</cfif>
<tr align="left" valign="center" bgcolor="<cfoutput>#strBgC
<td>
<cfoutput>#lcase(qryAM_Bal
</td>
<td align="center">
<cfoutput>#lcase(qryAM_Bal
</td>
<td align="center">
<input type="text" name="<cfoutput>#qryAM_Bal
</td>
</tr>
</cfloop>
</table>
<table width="600" border="0" cellspacing="0" cellpadding="1">
<tr align="right">
<td align="right">
<INPUT type="submit" value="add"> <INPUT type="reset" value="clear">
</td>
</tr>
</table>
</FORM>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I figured it out. I needed to have the same query from the form page on the results page and I needed to loop it to get all the variables.
If I gave the form a name, would I be able to output the variable using the form's name instead of using "Form"?
Like this: <cfoutput>#Balance_Form[qr yAM_Balanc es.NT_ID & "_ADD"]#</cfoutput>
If I gave the form a name, would I be able to output the variable using the form's name instead of using "Form"?
Like this: <cfoutput>#Balance_Form[qr
Well based on your code you have two choices.
1) send in the NT_ID value as a hidden variable
In that case you would access as:
<cfoutput>#Form[#Form.NI_I D_hidden#& "_ADD"]#</cfoutput>
2) Or you run the query again and then the error will go away.
1) send in the NT_ID value as a hidden variable
In that case you would access as:
<cfoutput>#Form[#Form.NI_I
2) Or you run the query again and then the error will go away.
>>If I gave the form a name, would I be able to output the variable using the form's name instead of using "Form"?
No.
"Form" is not due to a lack of a name. It is a scope. Like Session
You are saying "look in the form scope for a variable of this name"
The name of the form is really useless unless you need it for dynamic javascript on the form page
No.
"Form" is not due to a lack of a name. It is a scope. Like Session
You are saying "look in the form scope for a variable of this name"
The name of the form is really useless unless you need it for dynamic javascript on the form page
ASKER
Thanks for your help!
ASKER
Element NT_ID is undefined in QRYAM_BALANCES