Solved

Coldfusion retrieve dynamic values

Posted on 2016-10-04
1
47 Views
Last Modified: 2016-10-04
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
Comment
Question by:Errol Farro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 39

Accepted Solution

by:
gdemaria earned 500 total points
ID: 41828715
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is an updated version of a post made on my blog over 3 years ago. It is unfortunately, still very relevant as we continue to see both SQLi (SQL injection) and XSS (cross site scripting) attacks hitting some of the most recognizable website and …
Recently while working on a project I got a very annoying cfdocument has no body error message. I had never seen this error before. So I checked the code. The code was pretty simple; it was Just showing me the cfdocumnt tag and inside that tag a …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question