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
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("s") = "true" Then
CALL arrayProcessing
Else
CALL writeForm
End If
Sub arrayProcessing
dim cnt, q, e, j
dim arrR, arrQ, arrE
arrR = split(Request.Form("txtAddReg"), ",")
arrQ = split(Request.Form("txtQty"), ",")
arrE = split(Request.Form("hidEvt"), ",")
For i = 0 to UBound(arrQ)
q = arrQ(i)
e = arrE(i)
Response.Write "q = " & q & ", e = " & e & "<br>"
Next
End Sub
Sub writeForm
Response.Write "<form name='formtest' action='testloop.asp?s=true' method='post'>" & _
"<input type='text' name='txtQty' value='2'> " & _
"<input type='text' name='hidEvt' value='1234'><br>" & _
"<input type='text' name='txtAddReg' value=''><br>" & _
"<input type='text' name='txtAddReg' value=''><br><br>" & _
"<input type='text' name='txtQty' value='3'> " & _
"<input type='text' name='hidEvt' value='2345'><br>" & _
"<input type='text' name='txtAddReg' value=''><br>" & _
"<input type='text' name='txtAddReg' value=''><br>" & _
"<input type='text' name='txtAddReg' value=''><br><br>" & _
"<input type='text' name='txtQty' value='2'> " & _
"<input type='text' name='hidEvt' value='3456'><br>" & _
"<input type='text' name='txtAddReg' value=''><br>" & _
"<input type='text' name='txtAddReg' value=''><br><br>" & _
"<input type='submit' name='submit' value='submit'>" & _
"</form>"
End Sub
%>