[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 368
  • Last Modified:

How do I update a shopping cart session using a checkbox?

Dear Experts,

I am selling products that are all unique so I don't need to update cart quantities, but I do need to remove products using a check box the problem is the code I have so far removes all the products regardles of which check box I have selected. Code so far:

IF Request( "updateQ" ) <> "" THEN
FOR i = 0 TO UBOUND( localCart, 2 )
deleteProduct = TRIM(Request("pd" & localCart( CARTPID, i ) ) )
IF deleteProduct <> " " THEN
localCart( CARTPID, i ) = ""
ELSE
END IF
NEXT
END IF

<form name="form1" method="post" action="shop_cart.asp">
<input name="updateQ" type="hidden" value="1">

<td><%=Server.HTMLEncode( localCart( CARTPID, i ) )%></td>
<td><%=Server.HTMLEncode( localCart( CARTPNAME, i ) )%></td>
<td><%=formatCurrency( localCart( CARTPPRICE, i ) )%></td>
<td>input name ="pd<%=Server.HTMLEncode(localCart( CARTPID, i) )%>" type="checkbox" value="1">

<input type="submit" name="Submit" value="Update cart">

Many thanks
Tamz
0
morphy0186
Asked:
morphy0186
  • 5
  • 2
  • 2
1 Solution
 
fritz_the_blankCommented:
Okay, are you trying to remove a sesssion conent or an element from your array?

FtB
0
 
fritz_the_blankCommented:
Also, keep in mind that your check box is simply returning a value of 1 if it is checked and nothing at all if it is not checked.

FtB
0
 
morphy0186Author Commented:
I think an element from the array. The code to get the session shopping cart is:

IF NOT isArray( Session( "cart" ) ) THEN
DIM localCart( 4, 20 )
ELSE
localCart = Session( "cart" )
END IF

Is that what you wanted?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
fritz_the_blankCommented:
Okay, so what you want to do then is to wipe out an element in the cart based on a checkbox, is that it? And it looks like you are storing the array in a session variable? (Bad Idea!)

FtB
0
 
fritz_the_blankCommented:
In any event, I think that you problem is as follows:

IF Request( "updateQ" ) <> "" THEN
      FOR i = 0 TO UBOUND( localCart, 2 )
            deleteProduct = TRIM(Request("pd" & localCart( CARTPID, i ) ) )
            IF deleteProduct <> " " THEN
                  localCart( CARTPID, i ) = ""
            END IF
      NEXT
END IF

This code will delete all values if the request object does not equal space 1, i.e., " "

Perhaps you meant to say:

IF trim(deleteProduct) <> "" then


FtB
0
 
alorentzCommented:
Why aren't you using a database to store your cart?
0
 
morphy0186Author Commented:
Thank you very much for you help FtB.

alorentz, I am not using a database because I don't want users to have to login.
0
 
alorentzCommented:
>>, I am not using a database because I don't want users to have to login.

What makes you think that?  You absolutely DO NOT need users to login to use a database....
0
 
fritz_the_blankCommented:
Glad to have helped,

FtB
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 5
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now