Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Javascript shopping cart

Featured Replies

Hi everyone

 

My client has asked me to come up with a shopping cart and I want to know how to build one up in Javascript, if anyone has any ideas let me know

 

cheers

the best way would be a combination of AJAX (for ease of use) and PHP (for security).

 

What you can do is set up the "add to cart" button as a link which goes to, for example :

java script:addToCart( 62 );

where "62" is the unique ID number for that product.

 

The addToCart function then does a POST request to this URL:

backend.php?ajax=true&action=addToCart&productID=62

this backend.php page will recognise this (and other functions), and for this one, add the product ID to a cookie.

 

The standard cookie layout is that of an array like so:

Array(
 [23] = 1,
 [58] = 2,
 [62] = 2
)

 

Where the key ( in []) is the ID of the product and the value is the quantity required.

 

The backend.php script could also return an XML (JSON etc) or plain HTML string which updates the on-screen cart details.

 

If this sounds too complicated to achieve yourself, I am available to hire for such products so get in touch via PM.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.