473,383 Members | 1,818 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,383 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 4243
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.