0

I'm creating an ordering form for a photograph printing business with Adobe Acrobat 10. The concept is that the user will input data for each photograph individually - file name, paper size and paper type into cells in a table and a fourth column will calculate the price.

The paper size and paper type are drop down menus, Paper Size with 4 Options and Paper Type having 3 Options, so 12 combinations all with different prices.

I want a cell in the fourth column of each row to calculate the price based on the options the user has selected, but cannot reach this using addition/multiplication etc.

I have the concept that i need to write an IF statement with multiple conditions as in Excel but am not familiar with JavaScript and so need some help!

Thank you in advance!

Tom Stayte
  • 3
  • 1
  • 3

2 Answers2

0

I'm not familiar with the excel format myself, but in javascript you might have something like this :

if(paperType==1 && paperSize==1) {
    price = 13;
} else if(paperType==1 && paperSize==2) {
    price = 16;
} else if(paperType==2 && paperSize==1){
    price = 12;
} else {
    price = 27;
}

Of course there are many ways of dealing with this problem, from nesting the if statements to storing everything in a map/hash/object to using switch statements. Comparison naturally doesn't need to be against numbers, you could also use strings.

Frances McMullin
  • 5,516
  • 2
  • 18
  • 19
0

Make it an object and use it as a lookup-table to prevent too many if-else-statements:

var priceByPapersizeAndPapertype = {
    "A4": {
        "thick": 8.00,
        "medium": 13.50,
        "thin": …
    },
    "A5": {
         …
    },
    …
};

var size, type = …; // from form input
var price = priceByPapersizeAndPapertype[size][type];

If the user could enter invalid input, you can check for existance of the key with if (size in priceByPapersizeAndPapertype) and put an error message if needed.

Community
  • 1
  • 1
Bergi
  • 630,263
  • 148
  • 957
  • 1,375