Highlighted

Dynamic Form Values -Outputting

Participant ,
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.

Adobe Community Professional
Correct answer by Charlie Arehart | Adobe Community Professional

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.

Views

781

Likes

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

Dynamic Form Values -Outputting

Participant ,
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.

Adobe Community Professional
Correct answer by Charlie Arehart | Adobe Community Professional

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.

Views

782

Likes

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
Aug 15, 2019 0
Adobe Community Professional ,
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 (server troubleshooter, carehart.org)

Likes

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
Reply
Loading...
Aug 15, 2019 0
Participant ,
Aug 16, 2019

Copy link to clipboard

Copied

The master has spoken. Thank you, Charlie!

Likes

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
Reply
Loading...
Aug 16, 2019 1
Adobe Community Professional ,
Aug 16, 2019

Copy link to clipboard

Copied

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

/Charlie (server troubleshooter, carehart.org)

Likes

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
Reply
Loading...
Aug 16, 2019 0