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

Coldfusion retrieve dynamic values

I am using Jquery to produce dynamic text fields. The result of the form is as per the below.

How can I retrieve the content of myText[] for each field using Coldfusion?

<form method="post" action="collect_vals.cfm">
<div class="input_fields_wrap">
    <button class="add_field_button">Add More Fields</button>
    <div><input type="text" name="mytext[]"></div>
    <div><input type="text" name="mytext[]"></div>
    <div><input type="text" name="mytext[]"></div>
    <div><input type="text" name="mytext[]"></div>
    <div><input type="text" name="mytext[]"></div>
</div>
</form>
0
Errol Farro
Asked:
Errol Farro
1 Solution
 
gdemariaCommented:
When the form is submitted, the text input value is found in a variable of the form:

    form.myText

where myText is the name of the input field.

You cannot have brackets [] as part of your text input field's name.

Assuming the bracket is a sequential number such as  myText1, myText2, then to access the variable names dynamically, you can use a loop...
<cfloop index="kk" from=1 to="#form.numberRecords#">

   <cfset theValue = form["myTEXt" & kk]>
    --- the form field value is now in TheValue variable ---

</cfloop>

Open in new window

0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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