Zen Cart Logo
Forums / General Questions / Javascript calculation based on contents of shopping basket?

Javascript calculation based on contents of shopping basket?

Views: 1,298

Results 1 to 4 of 4
19 Sep 2011, 5:56 AM
#1
4lex avatar

4lex

New Zenner

Join Date:
Aug 2011
Posts:
16
Plugin Contributions:
0

Javascript calculation based on contents of shopping basket?

Hello all. I'm putting together a site that deals in energy efficient products. In an effort to incent sales I'd like to create a simple calculation that dynamically works out stuff based on the content of the shopper's basket.

One of the pieces of information on all of our product records is the power rating of the item in question, I'd like to be able to do some maths with this number and the quantity in the basket and display my answers in a sidebox.

Unfortunately my skills in javascript are pretty limited. I found some free scripts which I managed to modify to do the maths I want given inputs to an html table, and with the output written back to that table, so the maths part is doable.

Thing is I'm not sure how I might a) get variables from the cart application or b) put the output numbers in a sidebox.

Can anyone help?

Cheers,
Alex

23 Sep 2011, 1:06 AM
#2
4lex avatar

4lex

New Zenner

Join Date:
Aug 2011
Posts:
16
Plugin Contributions:
0

Re: Javascript calculation based on contents of shopping basket?

Please?

23 Sep 2011, 12:29 PM
#3
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,711
Plugin Contributions:
56

Re: Javascript calculation based on contents of shopping basket?

You're going to have to hire someone to do this for you.

24 Sep 2011, 6:38 AM
#4
rodg avatar

rodg

Deceased

Join Date:
Jan 2007
Location:
Australia
Posts:
6,263
Plugin Contributions:
4

Re: Javascript calculation based on contents of shopping basket?

4lex:

Thing is I'm not sure how I might a) get variables from the cart application or b) put the output numbers in a sidebox.

This isn't as simple as it may appear. What gets added to the cart is performed on the server. What you are wanting to output using javascript is performed by the client, so each time the customer adds a new item to the cart you'll need to have the client query the server for the updated data in order for the new calculations/display. To do this you'll be needing to employ AJAX technology.

If you are already comfortable with PHP and JavaScript then don't fear AJAX (too much), because this is a 'simple' technology that merges the two. There are lots of cut 'n' paste examples on the 'net that you can experiment with.

FWIW, I just love what AJAX has to offer, but it really makes my head spin and causes me all sorts of grief when coding/debugging it though.

Cheers
Rod