Link to home
Start Free TrialLog in
Avatar of wkolasa
wkolasaFlag for United States of America

asked on

CF - Concatenate question

Hi,

I have this:  #trim(getform.CFADMIN325)#

I want to use this variable:  <cfset resourceNum = 325>  to replace the 325 number above...

How would I write this out:  #getform.CFADMIN [variable.resourceNum]#

I tried this but it didn't work: #getform['CFADMIN' & resourceNum]#

Thanks for your help!
-Wendi

Avatar of erikTsomik
erikTsomik
Flag of United States of America image

can you try this

#trim(getform.CFADMIN325)#
<cfset resourceNum =#trim(right(getform.CFADMIN325,3))#>
Avatar of _agx_
If "getForm" is a query, you must supply a rownumber as well:

Example:
     #getform['CFADMIN' & resourceNum][1]#

... Or if you are looping through a query:

    <cfoutput query="getForm">
     #getform['CFADMIN' & resourceNum][ currentRow ]#
  </cfoutput>

Another, but  less elegant and performant option is to use Evaluate(...) .  

       #evaluate(getform['CFADMIN' & resourceNum])#
Avatar of wkolasa

ASKER

Agx,

First solution:  #getform['CFADMIN' & resourceNum][1]#  throws this error --

Element CFADMINRESOURCENUM is undefined in GETFORM.  
<input type="Text" name="#resourceNum#" value="#getform.CFADMINresourceNum#" size="30">

It's not evaluating the variable (<cfset resourceNum = 325>


Solution two:   #evaluate(getform['CFADMIN' & resourceNum])# throws this erro --

Complex object types cannot be converted to simple values.


First, is getForm a query?

> <input type="Text" name="#resourceNum#" value="#getform.CFADMINresourceNum#" size="30">
> It's not evaluating the variable (<cfset resourceNum = 325>

    That is different than what I posted.  It would be more like this:

    <input type="Text" name="#resourceNum#" value="##getform['CFADMIN' & resourceNum][1]#" size="30">
Correction:
    <input type="Text" name="#resourceNum#" value="#getform['CFADMIN' & resourceNum][1]#" size="30">

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of _agx_
_agx_
Flag of United States of America image

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 wkolasa

ASKER

yes, getForm is a query.  If I referenced the row I get the error:

[NA_SPO: coldfusion.sql.QueryColumn@f2fcb7] ] is not indexable by cf10o6


cf10o6 is one of the field names.

Avatar of wkolasa

ASKER

error created using this:  

<cfset eNum = 6>
<cfset textAreaName = "cf10o" & eNum>

#getform[textAreaName][getForm.currentRow]#
You must be something different in your code, because that works perfectly with a sample query.

<cfset getForm = QueryNew("cf10o6")>
<cfset queryAddRow(getForm, 1)>
<cfset querySetCell(getForm, "cf10o6", "See this test value? ...", 1)>

<cfset eNum = 6>
<cfset textAreaName = "cf10o" & eNum>
<cfoutput>
#getform[textAreaName][getForm.currentRow]#
</cfoutput>
> You must be something different in your code.

    You must be _doing_ something different in your code ..
... Though, as I mentioned it is more suitable for looping through a query:

     <cfoutput query="getForm">
           #getform['CFADMIN' & resourceNum][ currentRow ]#
     </cfoutput>


>> [NA_SPO: coldfusion.sql.QueryColumn@f2fcb7] ] is not indexable by cf10o6

irrc, such error is thrown when the value of the field is NULL...

Azadi
Avatar of wkolasa

ASKER

Thank you