Link to home
Start Free TrialLog in
Avatar of makila
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>#qryAM_Balances.NT_ID#</cfoutput>_ADD#</cfoutput> but it came back with an error. I tried <cfoutput>##<cfoutput>#qryAM_Balances.NT_ID#</cfoutput>_ADD##</cfoutput> 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>#strBgColor#</cfoutput>" class="tiny">
            <td>
                  <cfoutput>#lcase(qryAM_Balances.Rep_Name)#</cfoutput>
            </td>
            <td align="center">
                  <cfoutput>#lcase(qryAM_Balances.Current_Balance)#</cfoutput>
            </td>
            <td align="center">
                  <input type="text" name="<cfoutput>#qryAM_Balances.NT_ID#</cfoutput>_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>
ASKER CERTIFIED SOLUTION
Avatar of mrichmon
mrichmon

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of makila
makila

ASKER

I got the following error:

Element NT_ID is undefined in QRYAM_BALANCES

Avatar of makila

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[qryAM_Balances.NT_ID & "_ADD"]#</cfoutput>
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_ID_hidden#& "_ADD"]#</cfoutput>

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
Avatar of makila

ASKER

Thanks for your help!