• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Using a variable inside value

I am trying to use cfloop to get data from database. I want to put data in the value inside input text tag.

MyVar is a variable and it goes from 1 to 5.
How can I get value from database.
<input name="AfterFunding#MyVar#T" type="text" value="#others.AfterFunding#MyVar#T#">

So this tag should be <input name="AfterFunding1T" type="text" value="#others.AfterFunding1T#"> and it goes until 5T. the name is working but the value doesn't recognize it because there are two sets of ##.
1 Solution
Use array notation. Since it's a query object, you'll also need to supply a query row number

ie       #queryName["someFixedName"& counterVariableHere ][ rowNumber ]

.. translated, something like this, where "1" is the first row of the query

     value="#others["AfterFunding"& MyVar &"T"][1]#"

... or you're using cfloop query, use currentRow instead of hard coding the row number

<cfloop query="others">
     <input value="#others["AfterFunding"& MyVar &"T"][ currentRow]#" ....>
jkempleAuthor Commented:
Thank you. It works.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now