1 Reply Latest reply on Jun 28, 2007 10:31 AM by cf_dev2

    Creating Form Fields Based on Arrays

    FreddyBlogs
      I'm using MX7 and need to build up a variable number of fields in a form. Creating the variable list of fields to match number of items in list creates no problem -

      <cfloop index = "yy" from = "1" to = #List_No#>
      <cfinput type="text" name="DOB" id="DOB"/><br />
      </cfloop>

      That's fine. The problem is changing the name or ID of the field from DOB1 to DOB2 etc, and how does the the next page detect #Form.DOB1# and #Form.DOB2# etc.

      Thanks
        • 1. Re: Creating Form Fields Based on Arrays
          cf_dev2 Level 1
          Put the index after each field name
          <cfinput type="text" name="DOB#yy#" id="DOB"/>

          Store the #List_No# in a hidden field
          <input type="hidden" name="List_No" value="#List_No#">

          On the next page use the same kind of loop to grab the field names
          <cfloop index = "yy" from = "1" to = #form.List_No#>
          <cfoutput>
          form.DOB#yy# = form["DOB#yy#"]>
          </cfoutput>
          </cfloop>

          Obviously use cfoutput where needed.