Connecting Tech Pros Worldwide Forums | Help | Site Map

multiple inputs

Newbie
 
Join Date: Mar 2007
Posts: 15
#1: Mar 23 '07
Hi all, I need to implement multiple input fields that change depending on selections from the user. For example, A user may be prompted to enter data for multiple inputs who's names are incremented by 1 each time. So there would be
something like

Expand|Select|Wrap|Line Numbers
  1. <cfloop from="1" to="maxsize" index="i">
  2. <cfselect name="type#i#" size="1" query="get_type" value="ID" display="name">
  3. </cfselect>
  4. <cfselect>
  5.  
that works just fine, it is when I try to reference the form variable in the next page that things start breaking. If i use Form.type1 or Form.type2 to call the value it will work just fine. However I am not sure how I would use a loop to call the Form variables. Right now I am trying to do something like

sql statements blah blah
where band.ID='#Form.type&#i##'

but the Form.type and i do not concatenate correctly so it keeps erroring.

acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,750
#2: Mar 23 '07

re: multiple inputs


Welcome to TSDN - The Scripts.

Try this:
Expand|Select|Wrap|Line Numbers
  1. <CFLOOP COLLECTION="#Form#" ITEM="VarName">
  2.   <CFOUTPUT>
  3.     #VarName#: #Form[VarName]#<BR />
  4.   </CFOUTPUT>
  5. </CFLOOP>
or you can use the Form.FieldNames variable which contains all the form variables as a list. You can loop over them and use evaluate to get their values:
Expand|Select|Wrap|Line Numbers
  1. <CFLOOP INDEX="TheField" list="#Form.FieldNames#">
  2.   <CFOUTPUT>#TheField# = #Evaluate(TheField)#<BR /></CFOUTPUT>
  3. </CFLOOP>
Newbie
 
Join Date: Mar 2007
Posts: 15
#3: Mar 23 '07

re: multiple inputs


Thanks! :)
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,750
#4: Mar 23 '07

re: multiple inputs


You're welcome.
Reply