• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Dynamic Form Values -Outputting

Participant ,
Aug 15, 2019 Aug 15, 2019

Copy link to clipboard

Copied

I have a form that submits to itself like this

<form action="" method="post">

<table >

   <tr>

  <td width="50"><input type="checkbox" name="client_id_C" value="#client_id#"   ></td>

   <td  width="50"><input type="text"  name="#client_id#_Fee"  value="">  </td>

</tr>

</table>

</form>

The client_IDs are 101,102,103 etc

So when I fill out the form I get form values like this

101_Fee = 1000

102_Fee = 2000

103_Fee = 3000

I also get a list of the client_id's like

client_id_C = 20864,21238,21284

My question is once the form is submitted and the form reloads.

I want the fee values to populate the #client_id#_Fee text boxes, like this

<form action="" method="post">

<table >

   <tr>

  <td width="50"><input type="checkbox" name="client_id_C" value="#client_id#"   ></td>

   <td  width="50"><input type="text"  name="#client_id#_Fee"  value="#(#client_id#_Fee)#">  </td>

</tr>

</table>

</form>

Obviously what I have in red doesn't work

The problem is how do I code to get the value?

For example

I want the value for client_ID 101 to be 1000

Like this

<form action="" method="post">

<table >

   <tr>

  <td width="50"><input type="checkbox" name="client_id_C" value="101"   ></td>

   <td  width="50"><input type="text"  name="101_Fee"  value="1000">  </td>

</tr>

   <tr>

  <td width="50"><input type="checkbox" name="client_id_C" value="102"   ></td>

   <td  width="50"><input type="text"  name="102_Fee"  value="2000">  </td>

</tr>

</table>

</form>

What code goes in the value where the red text is.?

Because the variable already contains # tags.

Views

995

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Aug 15, 2019 Aug 15, 2019

Try:

<input type="text"  name="#client_id#_Fee"  value="#form["#client_id#"_Fee]#">

As a proof (that we are understanding what you mean), this produces the 1000 you seek:

<cfset form.101_Fee = 1000>

<cfset form.client_id=101>

<cfoutput>#form["#client_id#_fee"]#</cfoutput>

That said, when things get so convoluted, it's usually time to start reconsidering the design choices made for those form fields. But until then, this use of array notation to refer to a variable name built dynamically is a common so

...

Votes

Translate

Translate
Community Expert ,
Aug 15, 2019 Aug 15, 2019

Copy link to clipboard

Copied

Try:

<input type="text"  name="#client_id#_Fee"  value="#form["#client_id#"_Fee]#">

As a proof (that we are understanding what you mean), this produces the 1000 you seek:

<cfset form.101_Fee = 1000>

<cfset form.client_id=101>

<cfoutput>#form["#client_id#_fee"]#</cfoutput>

That said, when things get so convoluted, it's usually time to start reconsidering the design choices made for those form fields. But until then, this use of array notation to refer to a variable name built dynamically is a common solution for such challenges.

Let us know if that works for you.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

The master has spoken. Thank you, Charlie!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 16, 2019 Aug 16, 2019

Copy link to clipboard

Copied

LATEST

Well, I wouldn't put it that way, but thanks if that was indeed meant as a compliment. 🙂 And glad I could help.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation