473,230 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,230 software developers and data experts.

Shopping Cart Theory - Update cart VS Checkout

gregerly
192 Expert 100+
Hello,

I once again turn to this community of genius' for some help with a problem. I've got a shopping cart (which is working well so far) that I will be implementing all kinds of AJAX functionality on. However, first I want to make sure it works if javascript is not available. So when your on the shopping cart page, you can update the quantities then click Update Cart, which would update the totals, and refresh the shopping cart page, and then you could checkout. My question is: Without Javascript, how do I know if the user is trying to update the cart, or checkout? The cart in question can be found at:

Fresno SCORE

You have to add a workshop to the cart. Then you will see the cart page I'm talking about.

Thanks in advance!

Greg
Jul 27 '07 #1
15 4232
kovik
1,044 Expert 1GB
I haven't visited the site, but so you know, whenever you do anything in JavaScript, the non-JavaScript alternative needs to make sense. With AJAX, you can automatically update things behind the scenes. Otherwise, just have them post the data through a form and handle it server-side just like you would with AJAX.
Jul 27 '07 #2
gregerly
192 Expert 100+
I haven't visited the site, but so you know, whenever you do anything in JavaScript, the non-JavaScript alternative needs to make sense. With AJAX, you can automatically update things behind the scenes. Otherwise, just have them post the data through a form and handle it server-side just like you would with AJAX.
That is what my question is concerning. I know how to use AJAX responsibly, which is why I'm building it to work without Javascript first. But I have one form, with two buttons, UPDATE and CHECKOUT. How do I know that the user wants to UPDATE the cart rather than CHECKOUT and vice versa, when all the code is done on the server side?

Thanks,

Greg
Jul 27 '07 #3
kovik
1,044 Expert 1GB
That is what my question is concerning. I know how to use AJAX responsibly, which is why I'm building it to work without Javascript first. But I have one form, with two buttons, UPDATE and CHECKOUT. How do I know that the user wants to UPDATE the cart rather than CHECKOUT and vice versa, when all the code is done on the server side?

Thanks,

Greg
You check for the button upon submission. If you give the button a name attribute, then it will be submitted just like other elements of your form. Be aware that the form can be submitted without clicking a button, so make it so the first button in your form is the default if no button is sent.
Jul 27 '07 #4
gregerly
192 Expert 100+
I think I see where you are going with that volectricity. Does that mean that if I have two buttons in the form, say:

[HTML]<button name='update'>Update Cart</button>
<button name='checkout'>Checkout</button>[/HTML]

and I only click the "update" button, the checkout button is not submitted as part of the $_POST array? That will make things easy if this is the case. I'll try it and update here.

Thanks for the response!

Greg
Jul 28 '07 #5
kovik
1,044 Expert 1GB
I think I see where you are going with that volectricity. Does that mean that if I have two buttons in the form, say:

[HTML]<button name='update'>Update Cart</button>
<button name='checkout'>Checkout</button>[/HTML]

and I only click the "update" button, the checkout button is not submitted as part of the $_POST array? That will make things easy if this is the case. I'll try it and update here.

Thanks for the response!

Greg
In order to test it, you could simply print out the $_POST array and see what you get.

Expand|Select|Wrap|Line Numbers
  1. print_r($_POST);
Jul 28 '07 #6
gregerly
192 Expert 100+
Ok, figured it out. Only the button clicked is submitted with the form. I guess you learn something new everyday! Thanks for you help.

We can consider this case closed!

Greg
Jul 28 '07 #7
pbmods
5,821 Expert 4TB
Heya, Greg.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Jul 28 '07 #8
gregerly
192 Expert 100+
Time to reopen the case.

Issue:

In Firefox, IE7, a button is only is only included with the POST array if it's clicked. So, if you have two buttons on a form, only the one that was clicked will be submitted with the form.

In IE6, all buttons are included in the POST array regardless of if it was clicked or not. So, If I have a form (shopping cart) and I want to give the user the ability to update or checkout, I can't tell what he's trying to do as both buttons are submitted regardless of which one was clicked.

So, how can I tell what the user is trying to do? I'm thinking I'm going to have to use javascript.
Aug 2 '07 #9
Time to reopen the case.

Issue:

In Firefox, IE7, a button is only is only included with the POST array if it's clicked. So, if you have two buttons on a form, only the one that was clicked will be submitted with the form.

In IE6, all buttons are included in the POST array regardless of if it was clicked or not. So, If I have a form (shopping cart) and I want to give the user the ability to update or checkout, I can't tell what he's trying to do as both buttons are submitted regardless of which one was clicked.

So, how can I tell what the user is trying to do? I'm thinking I'm going to have to use javascript.
I have successfully implemented a solution to this problem by having two submit buttons:

Expand|Select|Wrap|Line Numbers
  1. <input type="submit" name="update cart" id="update cart" value="update cart" />
  2. <input type="submit" name="checkout" id="checkout" value="checkout" />
  3.  
When the form is submitted, use the server-side code to determine the value of the submit element of the POST array. Then you can determine what to do from there.

When you Ajaxify, you will use degradable javascript to add return false; to the onclick event handler for the submit buttons to stop the form from submitting, and since you have access to the id of the element clicked, you can submit to whatever page you desire.

Hope this helps,

-Jay
Aug 2 '07 #10
gregerly
192 Expert 100+
I have successfully implemented a solution to this problem by having two submit buttons:

Expand|Select|Wrap|Line Numbers
  1. <input type="submit" name="update cart" id="update cart" value="update cart" />
  2. <input type="submit" name="checkout" id="checkout" value="checkout" />
  3.  
When the form is submitted, use the server-side code to determine the value of the submit element of the POST array. Then you can determine what to do from there.

When you Ajaxify, you will use degradable javascript to add return false; to the onclick event handler for the submit buttons to stop the form from submitting, and since you have access to the id of the element clicked, you can submit to whatever page you desire.

Hope this helps,

-Jay
Hey Jay!

Thanks for the response. I switched over to the input type=submit and now things look like they are working great!

Nice work.

Greg
Aug 3 '07 #11
pbmods
5,821 Expert 4TB
Heya, Greg.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Aug 3 '07 #12
gregerly
192 Expert 100+
Heya, Greg.

Glad to hear you got it working! Good luck with your project, and if you ever need anything, post back anytime :)
Ok, I'm really starting to think pbmods just has that phrase in his clipboard ready to paste into any thread. :) Seriously....do you?

Greg
Aug 3 '07 #13
kovik
1,044 Expert 1GB
Ok, I'm really starting to think pbmods just has that phrase in his clipboard ready to paste into any thread. :) Seriously....do you?

Greg
*Starting* to think? :P
Aug 3 '07 #14
pbmods
5,821 Expert 4TB
Heya, Greg.

Ok, I'm really starting to think pbmods just has that phrase in his clipboard ready to paste into any thread. :) Seriously....do you?

Greg
That doesn't mean that I don't mean it :)

Now good luck with your project! *shove*
Aug 3 '07 #15
gregerly
192 Expert 100+
Heya, Greg.

That doesn't mean that I don't mean it :)

Now good luck with your project! *shove*

I know, with the amount of people the experts help here, It's probably a smart thing to do. Thanks to everyone who helps out around here!

Greg
Aug 3 '07 #16

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Don Grover | last post by:
USing ASP, MSSql on W2k3 I am worried of accumulated old cart product selections from expired browser windows or other unforseen events. I am holding selected productID's & quantities & userID...
9
by: Penny | last post by:
Hi all, I've built an online shopping cart using ASP Classic(based on a 'WebThang' tutorial). The shop cart page (with table showing customers selected items and costs) has only 3 buttons/links....
2
by: Paul Hobbs | last post by:
Hi All, I am developing a site that makes use of a standard shopping cart. Anyone can add items to the cart, but only registered users can actually check out. When a user tries to check out, if...
1
by: Adil Akram | last post by:
I have created a site shopping cart in ASP.net. I am using ASP session object's SessionID on non SSL connection to track session. While adding products to cart DB I insert product and SessionID...
2
by: G.E.M.P | last post by:
High Level Session Handling Design for a Shopping cart 0) What am I missing? 1) How does OSCommerce do it? I'm thinking about building a shopping cart from scratch, using a library of dynamic...
7
by: isaac2004 | last post by:
hi i have a basic asp page that acts as an online bookstore. on my cart page i am having trouble generating 3 numbers; a subtotal, a shipping total, and a final price. here is my code i would...
1
by: Vahehoo | last post by:
Hi, I have an ASP .Net e-business site that is built using DNN 2.0. I am having troubles passing my shopping cart items to PayPal. I implemented a total paynow button, but it was not good enough...
1
by: jecha | last post by:
I'm implementing a shopping cart but am having a problem in checking out a person who has added item in his/her shopping busket.The code for the checkout.php script is given below <?...
3
by: Paulo | last post by:
Hi, beginner on asp.net 2.0 C# VS 2005, how can I use the shopping cart concept on my application? When the user clicks add item, it will be stored on some storage format, I dont know what is the...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.