Dynamic form. name

ChirsJB
ChirsJB used Ask the Experts™
on
I want to create a dynamic Serial Number entry screen.  The number of input boxes will be determined by the number of SN that need to be entered.  The problem is accessing the sn's in the action screen. How can I access the sn in the action screen.


FORM SCREEN

<CFLOOP INDEX="SN_Item" FROM="1" TO="#variables.sn_qty#" STEP="1">
<TABLE>
<TR>
      <TD>Serial Number Item: #SN_Item#</TD>
      <TD><INPUT TYPE="text"
       NAME="SN#SN_ITEM#"
       SIZE="10"
       MAXLENGTH="10"></TD>
</TR>
</TABLE>
</CFLOOP>

I can validate the form variables but I can't reach the data.

ACTION SCREEN

<CFIF NOT IsDefined("Form.SN_Qty")>
  SN QTY: You reached this page in error.
  <cfabort>
</CFIF>

<!--- validate Form.SN --->
<CFLOOP INDEX="SN_Item" FROM="1" TO="#Form.SN_Qty#" STEP="1">
  <CFIF NOT IsDefined("Form.SN#SN_ITEM#")>
    <br>SN:#SN_ITEM#: You have reached this page in error.
    <cfabort>
  <CFELSE>
          READ/GET DATA HERE!!!
  </CFIF>
</CFLOOP>


Chris

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
The way to reach the data is to use Evaluate("Form.SN#SN_ITEM#").  That will dynamically evaluate the variable name and return its value.

e.g., inside your validation cfloop after the cfelse:

<cfset thesn=evaluate("Form.SN#SN_ITEM#")>

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial