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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help displaying output from three arrays

Status
Not open for further replies.

aprilius

Programmer
Apr 23, 2002
7
0
0
US
I am working on a shopping cart type of application for event registration. The client wants textboxes for entering email addresses to be displayed if the quantity of the event in the shopping cart is more than one. The client does not want any buttons to save the email addresses on each line item - she wants all the email addresses for each line item to be saved when the shopping cart form is submitted.

I put the quantity ordered value into a hidden form field, and the event number into a hidden form field. The email addresses are then inputed into text boxes by the customer.

I named all of the input fields for each line item the same thing, so when the form is submitted, I split the results into three separate arrays: the first for quantities, the second for event numbers, and the third for the email addresses. The quantity and event number arrays will always have the same number of indices. The email array will always be larger.

I am getting hung up on associating the three though. I know that that for each index in the quantity and event arrays, they will always match. The problems comes in when I am trying to match up the quantity/event with the emails. If the value of a given index in the quantity array is equal to three for instance, I want to output the first three items in the email array. If the value of the next index in the quantity array is 2, then output the next two items in the email array.

I am still debugging things so that I get it right before I do inserts into the database, so I am just response.write - ing all out. I keep coding this wrong and causing infinite loops, so I just stripped it out. You want see any reference to me looping through it at all - just the creation of it. i just created a test page to figure this out. The actual output in the other application is dynamic - so I never know how big each array is going to end up being.

thanks for your help.
april

Code:
<%
If Request.QueryString(&quot;s&quot;) = &quot;true&quot; Then
	CALL arrayProcessing
Else
	CALL writeForm
End If

Sub arrayProcessing
	dim cnt, q, e, j
	dim arrR, arrQ, arrE

	arrR = split(Request.Form(&quot;txtAddReg&quot;), &quot;,&quot;)
	arrQ = split(Request.Form(&quot;txtQty&quot;), &quot;,&quot;)
	arrE = split(Request.Form(&quot;hidEvt&quot;), &quot;,&quot;)

	For i = 0 to UBound(arrQ)
		q = arrQ(i)
		e = arrE(i)
		Response.Write &quot;q = &quot; & q & &quot;, e = &quot; & e & &quot;<br>&quot;
	Next
End Sub

Sub writeForm
	Response.Write &quot;<form name='formtest' action='testloop.asp?s=true' method='post'>&quot; & _
	&quot;<input type='text' name='txtQty' value='2'>  &quot; & _
	&quot;<input type='text' name='hidEvt' value='1234'><br>&quot; & _
	&quot;<input type='text' name='txtAddReg' value=''><br>&quot; & _
	&quot;<input type='text' name='txtAddReg' value=''><br><br>&quot; & _

	&quot;<input type='text' name='txtQty' value='3'>  &quot; & _
	&quot;<input type='text' name='hidEvt' value='2345'><br>&quot; & _
	&quot;<input type='text' name='txtAddReg' value=''><br>&quot; & _
	&quot;<input type='text' name='txtAddReg' value=''><br>&quot; & _
	&quot;<input type='text' name='txtAddReg' value=''><br><br>&quot; & _

	&quot;<input type='text' name='txtQty' value='2'>  &quot; & _
	&quot;<input type='text' name='hidEvt' value='3456'><br>&quot; & _
	&quot;<input type='text' name='txtAddReg' value=''><br>&quot; & _
	&quot;<input type='text' name='txtAddReg' value=''><br><br>&quot; & _

	&quot;<input type='submit' name='submit' value='submit'>&quot; & _
	&quot;</form>&quot;
End Sub

%>
 
Sub arrayProcessing
dim cnt, q, e, i, j
dim arrR, arrQ, arrE
dim topval, botval
botval = 0
arrR = split(Request.Form(&quot;txtAddReg&quot;), &quot;,&quot;)
arrQ = split(Request.Form(&quot;txtQty&quot;), &quot;,&quot;)
arrE = split(Request.Form(&quot;hidEvt&quot;), &quot;,&quot;)


For i = 0 To UBound(arrQ)
q = arr(i)
topval = q + botval
response.write &quot;q = &quot; & q & &quot;, &quot;
For j = botval To topval - 1
e = arr2(j)
response.write &quot;e = &quot; & e & &quot;, &quot;
Next
response.write &quot;<BR>&quot;
botval = topval
Next
 
sjravee,

I am hereby declaring to the world that you are my bectest friend! Thanks so much, it worked like a charm!

april [love]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top