Avatar of Andrew Angell
Andrew Angell
Flag for United States of America asked on

How to loop through a form's checked check box items to add each one to my shopping cart...???

I use a 3rd party shopping cart that's very easy to configure for adding single items to a cart. It's not very well setup, though, for creating 1 form of products with check boxes and adding every checked item to the cart with a single form submission.

I'm trying to do this manually by creating the form myself and calling the add to cart function the shopping cart software uses for each checked item.  Does this sound like how I should do it?

If so, how do I do that? lol.  When the form is submitted how do I loop through each of the check boxes that are checked?  The products with check boxes are listed dynamically on the page.  The check box names are all ATCCheck and the checked values of each is its productID.  

The form also includes a hidden form field with another product that needs to be included in the loop and added at the same time as everything else.

Any information would be greatly appreciated.  Thanks!
E-CommerceASP

Avatar of undefined
Last Comment
Andrew Angell

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
amit_g

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Andrew Angell

ASKER
Well, shoot.  I may have jumped the gun.  Would you mind taking a look and seeing what I've done wrong here?  I have the following:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="WA_eCart/WA_eCart_Definition_VB.asp" -->
<!--#include file="WA_eCart/kennysCart_VB.asp" -->
<!--#include file="Connections/connKennysMDIData.asp" -->
<%
checkedProducts = Request.Form("ATCCheck")
checkedProductsSplit = Split(checkedProducts,",")
for i = LBound(checkedProductsSplit) to UBound(checkedProductsSplit)
%>
<%
Dim rsAddedItems
Dim rsAddedItems_cmd
Dim rsAddedItems_numRows

Set rsAddedItems_cmd = Server.CreateObject ("ADODB.Command")
rsAddedItems_cmd.ActiveConnection = MM_connKennysMDIData_STRING
rsAddedItems_cmd.CommandText = "SELECT kennysInventoryID, productDescription1, productID, productName, unitPrice, weight FROM products  WHERE productID = "&i&""
rsAddedItems_cmd.Prepared = true

Set rsAddedItems = rsAddedItems_cmd.Execute
rsAddedItems_numRows = 0
%>
<%
'WA eCart Get Info From RS
if ("" = "")     then
  Redirect_redirStr = "shoppingCart.asp"
  while (NOT rsAddedItems.EOF)
    kennysCart_itemID = cDbl("" & cStr((rsAddedItems.Fields.Item("productID").Value)) & "")
    kennysCart_itemName = "" & cStr((rsAddedItems.Fields.Item("productName").Value)) & ""
    kennysCart_itemDescription = "" & cStr((rsAddedItems.Fields.Item("productDescription1").Value)) & ""
    kennysCart_itemWeight = cDbl("" & cStr((rsAddedItems.Fields.Item("weight").Value)) & "")
    kennysCart_itemQuantity = cDbl("1")
    kennysCart_itemPrice = cDbl("" & cStr((rsAddedItems.Fields.Item("unitPrice").Value)) & "")
    set kennysCart = kennysCart_AddToCart(1, "", kennysCart_itemID, kennysCart_itemName, kennysCart_itemDescription, kennysCart_itemWeight, kennysCart_itemQuantity, kennysCart_itemPrice)
    rsAddedItems.MoveNext()
  wend
  if (rsAddedItems.CursorType > 0)     then
    if (NOT rsAddedItems.BOF)     then
      rsAddedItems.MoveFirst()
    end if
  else
    rsAddedItems.Requery()
  end if
  if (Redirect_redirStr <> "")     then
    kennysCart_redirStr = Redirect_redirStr
  end if
end if
%>
<%
' WA eCart Redirect
if (kennysCart_redirStr <> "")     then
  Response.Redirect(kennysCart_redirStr)
end if
%>

<%
Next
%>

<%
rsAddedItems.Close()
Set rsAddedItems = Nothing
%>


And it's adding a whole bunch of products to the shopping cart instead of just the few that are in the form.  Not sure how it's grabbing them...they're pretty random.
amit_g

Change
FROM products  WHERE productID = "&i&""
to
FROM products  WHERE productID = "& checkedProductsSplit (i) &"" 
Andrew Angell

ASKER
Ok, that fixed that.  Thank you.  I am having another issue, though, explained for extra points in this thread: https://www.experts-exchange.com/Web/Web_Languages/ASP/Q_21984932.html.

Basically I have 2 tables within the form that's getting submitting that dynamically generate check boxes for items.  All check box names are the same and reside within the same form, but only the second table's check boxes are working.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy