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!

How check form values of dynamically named text boxes

Status
Not open for further replies.

aprilius

Programmer
Apr 23, 2002
7
US
I am going to do the best I can describing the trouble I am having.

I inherited a shopping cart type application that allows users to sign up for courses online. I did not write this application, but now I need to add enhancements to it.

If a user registers for a quantity of more than one for a given course, the number of text boxes to be displayed will equal the quantity chosen... if they register for a quantity of one, there will be no text box. So if I register for a quantity of one, there will be no text boxes. If I register for a quantity of three, there will be three text boxes. In these text boxes, the user will enter the email addresses of the other people they would like to register for a given course.

So here's my problem. When I submit this request for processing, how do I grab the email addresses entered into those textboxes (if there are any textboxes at all)? I am not sure how to name them, or loop through them to get their values. I want to grab those email address (if there are any) and do an insert into the database, along with the course number and session id. And I am further confused by the fact that there can be more than one course in the shopping cart...

Here's an excerpt from the code I have so far. I have tried multiple ways to get this to work, to no avail.

Code:
Sub ShowCart
		Response.Write&quot;<TABLE Border='0' CellPadding='3' CellSpacing='0' width='100%'>&quot; & _
		&quot;<TR><TD> </TD><TD>&quot; & _
		&quot;<TABLE Border='0' CellPadding='3' CellSpacing='0' width='100%'>&quot; & _
		&quot;<TR><TD class='txtB14Blue' colspan='3'>Verify Your Order</td></TR>&quot; & _
		&quot;<TR><TD class='txtB10' width='7%' valign='bottom' align='center'>Quantity</td>&quot; & _
		&quot;<TD class='txtB10' width='63%' valign='bottom' align='center'>Description</TD>&quot;
				IF bMember = False Then
					Response.Write &quot;<TD class='txtB10' width='15%' valign='bottom' align='right'>Non-Member Price</TD></TR>&quot;
				Else
					Response.Write &quot;<TD class=txtB10 width='15%' valign='bottom' align='right'>Member Price</TD></TR>&quot;
				End If
		Response.Write &quot;<tr><td colspan='3' align='center'><hr color='#000099' width='100%'></td></tr>&quot;
		fTotalM = 0
		fTotalNonM = 0
		iCount = 0
		sSQL = &quot;SELECT Member_Fee, Non_Member_Fee, Shop.Description Descript, Title, Shop.Quantity, CAST(Event AS Int) As EvNo &quot; & _
		&quot; FROM RP_Event, Orders_ShopCart As Shop WHERE RP_Event.RP_Event_Id=Shop.Event AND Shop.SessionID=&quot; & Session.SessionID
		Set RS = ConnectED.Execute(sSQL)

		DO While Not RS.Eof
				iCount = iCount + 1
				IF iCount MOD 2 = 0 THEN
					Response.Write &quot;<TR bgcolor='#E8ECF9'>&quot; & _
					&quot;<TD class='txt10' align='center' valign='top'>&quot;
						IF RS(&quot;Quantity&quot;) = 1 Then
							Response.Write RS(&quot;Quantity&quot;) &&quot;</td>&quot; & _
							&quot;<TD class='txt10'>&quot; & RS(&quot;Descript&quot;) & &quot;, &quot; & RS(&quot;Title&quot;) & &quot;<br></TD>&quot;
								IF bMember = False Then
									Response.Write &quot;<TD class='txt10' align='right' valign='top'>$ &quot; & FormatNumber(RS(&quot;Quantity&quot;) * RS(&quot;Non_Member_Fee&quot;), 2) & &quot;</TD></TR>&quot;
								ELSE
									Response.Write &quot;<TD class='txt10' align='right' valign='top'>$ &quot; & FormatNumber(RS(&quot;Quantity&quot;) * RS(&quot;Member_Fee&quot;), 2) & &quot;</TD></TR>&quot;
								END IF
						ELSE
							Response.Write RS(&quot;Quantity&quot;) &&quot;</td>&quot; & _
							&quot;<TD class='txt10'>&quot; & RS(&quot;Descript&quot;) & &quot;, &quot; & RS(&quot;Title&quot;) & &quot;<br></TD>&quot;
								IF bMember = False Then
									Response.Write &quot;<TD class='txt10' align='right' valign='top'>$ &quot; & FormatNumber(RS(&quot;Quantity&quot;) * RS(&quot;Non_Member_Fee&quot;), 2) & &quot;</TD></TR>&quot;
								ELSE
									Response.Write &quot;<TD class='txt10' align='right' valign='top'>$ &quot; & FormatNumber(RS(&quot;Quantity&quot;) * RS(&quot;Member_Fee&quot;), 2) & &quot;</TD></TR>&quot;
								END IF

							Response.write &quot;<tr bgcolor='#E8ECF9'><td> </td><td class='txt8Blue'><i>You ordered a quantity of more than one for the same course. Please enter the email address(es) of the additional registrant(s).</i></td><td> </td></tr>&quot;

							Dim qtyCnt
							qtyCnt = 0

							Do Until qtyCnt = RS(&quot;Quantity&quot;)
								qtyCnt = qtyCnt + 1
								Response.Write &quot;<tr bgcolor='#E8ECF9'><td> </td><td class='txt8Blue'>Registrant #&quot; & qtyCnt & &quot;: <input type='text' name='txtAddReg&quot; & EvNo & &quot;[&quot; & qtyCnt & &quot;]' width='25' value=''></td><td> </td></tr>&quot;
							Loop
						END IF
				ELSE
					Response.Write &quot;<TR bgcolor='#ffffff'>&quot; & _
					&quot;<TD class='txt10' align='center' valign='top'>&quot;
						IF RS(&quot;Quantity&quot;) = 1 Then
							Response.Write RS(&quot;Quantity&quot;) &&quot;</td>&quot; & _
							&quot;<TD class='txt10'>&quot; & RS(&quot;Descript&quot;) & &quot;, &quot; & RS(&quot;Title&quot;) & &quot;<br></TD>&quot;
								IF bMember = False Then
									Response.Write &quot;<TD class='txt10' align='right' valign='top'>$ &quot; & FormatNumber(RS(&quot;Quantity&quot;) * RS(&quot;Non_Member_Fee&quot;), 2) & &quot;</TD></TR>&quot;
								ELSE
									Response.Write &quot;<TD class='txt10' align='right' valign='top'>$ &quot; & FormatNumber(RS(&quot;Quantity&quot;) * RS(&quot;Member_Fee&quot;), 2) & &quot;</TD></TR>&quot;
								END IF
						ELSE
							Response.Write RS(&quot;Quantity&quot;) &&quot;</td>&quot; & _
							&quot;<TD class='txt10'>&quot; & RS(&quot;Descript&quot;) & &quot;, &quot; & RS(&quot;Title&quot;) & &quot;<br></TD>&quot;
								IF bMember = False Then
									Response.Write &quot;<TD class='txt10' align='right' valign='top'>$ &quot; & FormatNumber(RS(&quot;Quantity&quot;) * RS(&quot;Non_Member_Fee&quot;), 2) & &quot;</TD></TR>&quot;
								ELSE
									Response.Write &quot;<TD class='txt10' align='right' valign='top'>$ &quot; & FormatNumber(RS(&quot;Quantity&quot;) * RS(&quot;Member_Fee&quot;), 2) & &quot;</TD></TR>&quot;
								END IF

							Response.write &quot;<tr bgcolor='#ffffff'><td> </td><td class='txt8Blue'><i>You ordered a quantity of more than one for the same course. Please enter the email address(es) of the additional registrant(s).</i></td><td> </td></tr>&quot;

							Dim qntyCnt
							qntyCnt = 0

							Do Until qntyCnt = RS(&quot;Quantity&quot;)
								qntyCnt = qntyCnt + 1
								Response.Write &quot;<tr bgcolor='#ffffff'><td> </td><td class='txt8Blue'>Registrant #&quot; & qtyCnt & &quot;: <input type='text' name='txtAddReg&quot; & EvNo & &quot;[&quot; & qtyCnt & &quot;]' width='25' value=''></td><td> </td></tr>&quot;
							Loop
						END IF
				END IF

				fTotalM = fTotalM + (RS(&quot;Quantity&quot;) * RS(&quot;Member_Fee&quot;))
				fTotalNonM = fTotalNonM + (RS(&quot;Quantity&quot;) * RS(&quot;Non_Member_Fee&quot;))
				RS.MoveNext
		Loop

			If iCount  > 0 Then
				Response.Write &quot;<TR><TD ALIGN='Right' colspan='2' class='txtB10' valign='bottom'><br><br>Total: </TD>&quot;
					IF bMember = False Then
						Response.Write &quot;<TD ALIGN='right' class='txtB10' valign='bottom'>$ &quot; & FormatNumber(fTotalNonM,2) & &quot;</TD></TR>&quot;
					ELSE
						Response.Write &quot;<TD ALIGN='right' class='txtB10' valign='bottom'>$ &quot; & FormatNumber(fTotalM,2) & &quot;</TD></TR>&quot;
					END IF
					Response.Write &quot;<tr><td colspan='3' align='right'><br><br><a href='EmailOrder.asp'>Email Order to Customer Service <img src='images/Icon_GoldArrow.gif' border ='0'></a>    <a href='&quot; & sSecureSite & &quot;AskInfo.asp'>Place Order Now Using Credit Card <img src='images/Icon_GoldArrow.gif' border='0'></a></td></tr></table>&quot;
			Else
				Response.Write &quot;<TR><TD ALIGN='center' colspan='3' class='txtB10'>No Items on your Order</TD></TR></TABLE>&quot;
			End If
End Sub
 
Ok, I didn't read all the way through your code because i think I have a solution for you (sorta). Your problem is that you need to read, dynamically, 0 to n form values. i noticed the txt boxes are named with []'s so at least reading them back will not be to bad. What you will want to do is to set up a while loop with a counter.
Code:
<%
Dim counter
counter = 0 
Do While Request(&quot;inputName[&quot;&counter&&quot;]&quot;) <> &quot;&quot;
   Response.Write &quot;value &quot;&counter&&quot; is &quot;& Request(&quot;inputName[&quot;&counter&&quot;]&quot;)
   counter = counter + 1
Loop
%>
This should loop through all of the inputs until it hits a blank or null, which will occur when it runs out of form inputs.

I should have thought of this earlier, but you could always pass the # of inputs in a hidden field and just do a for loop. :p

-Tarwn
I'm not blind, I just forget the words faster than I can read 'em
 
Hi,

I am not sure what you are looking for, but I think it can be done. What does the e-mail address an courses have to do with each other?

-Uncle Cake
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top