Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Action Page Problem 3

Status
Not open for further replies.

jimmyshoes

Programmer
Jun 1, 2008
132
GB
I have been given a dynamic form in javascript which depending on user input sends a number of form variables. For example, if the user enters 3 boxes it sends the following form variables ar_1, ar_2 and ar_3 . If the user enters 4 it sends ar_1, ar_2, ar_3 and ar_4 etc

What I want to do is to create a list out of these values in my action page ( in the same way that a group of checkbox items are rendered as a list of values by the browser) But I'm at a loss as to how to go about this. Any suggestions gratefully accepted
 
Are the checkboxes dynamic?

If not try:

Code:
Action Page:
<cfset ar_List=''>
<cfif IsDefined("Form.ar_1">
 <cfset ar_List=ar_List+'ar_1,'>
</cfif>
<cfif IsDefined("Form.ar_2">
 <cfset ar_List=ar_List+'ar_2,'>
</cfif>
<cfif IsDefined("Form.ar_3">
 <cfset ar_List=ar_List+'ar_3,'>
</cfif>
<cfif IsDefined("Form.ar_4">
 <cfset ar_List=ar_List+'ar_4,'>
</cfif>

If it is dynamic you need to share some of the code.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
If the user enters 4 it sends ar_1, ar_2, ar_3 and ar_4 etc

If you know the total number of fields, store that value in a separate form field. On your action page, use it to construct a cfloop. Inside the loop use the "index" variable to construct the form field names: form.ar_1, form.ar_2, etcetera. Then append each value to your list.

The general concept is below. Be aware the code assumes your fields are textboxes (ie they always exist). If your fields are checkboxes or radio buttons you will need to add additional handling.

Code:
<!--- not tested --->
<cfset yourList = "">
<cfloop from="1" to="#form.numberOfFields#" index="counter">
     <cfset yourList = listAppend(yourList, form["ar_"& counter]>
</cfloop>

<cfoutput>
yourList = #yourList#
</cfoutput>


----------------------------------
 
on the action page just use form.fieldnames this is a list of all fields submited by the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top