Click to See Complete Forum and Search --> : HELP needed please.


michael
02-24-2003, 06:29 PM
Hi all this is my first post so hopefully someone here can help.

I am setting up a Java shopping cart called JShop. It is all installed and it works fine, however I am trying to make the form calculate a discount percentage based on how many products are ordered.

Now I am very, very new to Java but I have already made a start to the script.

Below is what I have so far...

This part selects the correct percentage:

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin percentage
function findPercentage() {
var units = getNumberOfUnits();
var percentage = getPercentage(units);
return percentage;
}
function getNumberOfUnits() {
var units = allitems;
return units;
}
function getPercentage(units) {
if (units >= 100) return 45;
if (units >= 70) return 40;
if (units >= 40) return 35;
if (units >= 20) return 30;
if (units >= 10) return 25;
if (units <= 9) return 0;
}
// End percentage -->

<!-- Begin discount
function findDiscount() {
var numofblends = getNumberOfBlends();
var newpriceofblends = getNewPrice(numofblends);
var newprice = (numofblends*newpriceofblends)/100
return newprice;
}
function getNumberOfBlends() {
var numofblends = allitems;
return numofblends;
}
function getNewPrice(numofblends) {
if (numofblends >= 100) return 659;
if (numofblends >= 70) return 719;
if (numofblends >= 40) return 779;
if (numofblends >= 20) return 839;
if (numofblends >= 10) return 899;
if (numofblends <= 9) return 1199;
}
// End discount -->

Basically what I need to know is what it the correct way to make an equation that will find the percentage of a number?

Eg. 25% of £128.86p or 45% of 47.45p etc....

Any help would be most appreciated.

Thanks.

michael
02-24-2003, 07:54 PM
Thanks Dave, that worked just fine.
OK one last question for you or anyone else that reads this.

I think there is a loop in the function that makes the table which has all the products in it.
What I need to do is create a variable that increments itself by 1 each time an item is added to the table.
When the table (order form) is done, the variable should have a value equal to the ammount of items in the table, this will then allow the script to determin what discount percentage to use.

Hope I'm making sence.

So could someone take a look at this page...
www.katseyeblends.co.uk/orderform.html

It's the start of the order form. It's the very last page that creates the actual order form (anyone who has used JShop will see this).

What I need is someone to show me where I can place a variable that will increment itself.

If someone can have a look I'd be very grateful.

Thank you.