How can I access an HTML form field in CF when I need to use a loop index variable?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Keith Pastorek
    New Member
    • Dec 2010
    • 1

    How can I access an HTML form field in CF when I need to use a loop index variable?

    So I have a form that has an array passed in. When generating the online form, I loop through the array and create the same text boxes for each value in the array. So my text boxes (relating to landscaping) have names like mow1 for the first array value, mow2 for the second, etc. When I submit the form I need to loop through the form fields in my cf code, to send each mini-form to a stored procedure that saves teh values in a database. Below is some code (with just one field as an example) of what I need to do. For the form field I need to capture the value of form.mow1, form.mow2, etc., but I can't get it to accept the form name using the index value of i added to the name. Is there a way to reference that form field differently that would let me concatenate the index number of i to the name, so it could read teh value corrctly? I will appreciate any help I can get on this one. Thanks.

    Code:
    <cfloop index="i" from="1" to="#ArrayLen(storeArr)#">
     <cfscript>
      StoredProc.createProcedure("sp_inst_landscaping");
      StoredProc.addINParameter("CF_SQL_NUMERIC",form.mow&i,0);
      StoredProc.executeProcedure();
     </cfscript>	
    </cfloop>
    Last edited by acoder; Jan 14 '11, 04:08 PM.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    You can use something like form["mow" & i]

    Comment

    Working...