Solved

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

Posted on 2004-09-13
9
316 Views
Last Modified: 2012-05-05
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
Comment
Question by:morphy0186
  • 5
  • 2
  • 2
9 Comments
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12048355
Okay, are you trying to remove a sesssion conent or an element from your array?

FtB
0
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12048375
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
 

Author Comment

by:morphy0186
ID: 12048444
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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12048475
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 46

Accepted Solution

by:
fritz_the_blank earned 500 total points
ID: 12049314
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
 
LVL 31

Expert Comment

by:alorentz
ID: 12049496
Why aren't you using a database to store your cart?
0
 

Author Comment

by:morphy0186
ID: 12052296
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
 
LVL 31

Expert Comment

by:alorentz
ID: 12052683
>>, 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
 
LVL 46

Expert Comment

by:fritz_the_blank
ID: 12060287
Glad to have helped,

FtB
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now