1

I have a complex pricing form that I created in Excel to use for all my quoting, however quoting is becoming more and more time consuming and I wanted to create a PDF version that people can tweak options to fit their budget.

I've tried to figure out Javascript but the formatting is alien and I can't find anybody who has created a similar calculation, is anybody able to help ?

There will be multiple 'sections' where the totals of each section will be calculated into a grand total, but each 'section' is basically the same.
But the trick is that I would like each 'section' to have a base cost that only shows after a valid quantity is entered (eg. 25+).
Each radio button 'choice' has to have a unique value also, eg. SizeChoice1=1, SizeChoice2=2, SizeChoice3=3.
So a summary of the content (excel style) is:

if QTY >25 (250+(SizeChoice(1,2or3)*QTY)+(ColourChoice(1,2or3)*QTY)+StockChoice(1,2or3)*QTY), if QTY<25 = 0

And also preferably a total that is rounded up, if possible.

4
  • In my opinion your question is too broad, maybe you can split this in several smaller questions?
    – yms
    Oct 28, 2014 at 19:18
  • The most important part is this:
    – ncman
    Oct 28, 2014 at 21:49
  • if QTY >25 (250+(SizeChoice(1,2or3)*QTY)+(ColourChoice(1,2or3)*QTY)+StockChoice(1,2or3)*QTY), if QTY<25 = 0 I don't understand how to make that any smaller, it's all part of the same equation.
    – ncman
    Oct 28, 2014 at 21:50
  • I suppose I only need if QTY >25 (250+(SizeChoice(1,2or3)*QTY), if QTY <25 = 0 and I can repeat the other steps
    – ncman
    Oct 28, 2014 at 21:52

1 Answer 1

1

Are the choices mutually exclusive? Probably not. But if so, you would use checkboxes instead of radio buttons, give the ones which belong together the same name, but a different return value. And they behave like radio buttons.

It is a very good idea to not want to simply translate an Excel formula into (Acrobat) JavaScript, because the concepts behind Excel formulas and Acrobat JavaScript are too far away, and it is only the question when you horrendously fall on your nose (I know what I am talking about; I have been burnt too many times when I was in a good mood and agreed to turn the client's Excel spreadsheet into a PDF form.

What you would do instead is do a quick analysis of the form, and what it should do. And then, you can build up the form following that logic. Keep in mind that (Acrobat) JavaScript allows to create loops (ideal when you have functional blocks, and use a counter in their field names), or functions (which you can call wherever you need, passing arguments). Also keep in mind the field event sequence, which has the great side effect that you can consolidate all the logic into one single field, which is not even part of the fields being involved in the calculation.

In your case, the calculation does depend a lot on the choice of the field names. Do it well, your code is short and elegant, do it not so well, your code will be a mess.

Now, for your example, there is not sufficient information on what it should do. So, it might be a good idea to add the findings of your quick analysis to the question.

I think I know what you want to do, and in this case, the whole thing gets pretty simple.

6
  • Thank you Max. I am not sure what you mean by mutually exclusive? The reason I chose radio buttons over checkboxes is the fact I don't want people to be able to select two options. It has to be A, B or C. If they accidentally check two and don't realise the price will be incorrect. There is a base fee that goes with size option. Then the price climbs based on quantity, stock choice, other extras etc. Each of these has an X value for each single item. But we need a minimum order QTY also as it's not possible to order only one.
    – ncman
    Oct 30, 2014 at 6:46
  • Also the reason why I included the IF statement was so that if a radio button was checked (and can't be unchecked) the whole form doesn't need to be cleared and start again. If the IF statement reverted to $zero when a QTYzero value was entered it means they aren't affecting the grand total.
    – ncman
    Oct 30, 2014 at 6:48
  • mutually exclusive indeed means that only one of the choices, A, B, or C is possible, and that selecting a non-selected choice will reset the other ones.
    – Max Wyss
    Oct 30, 2014 at 8:41
  • 1
    The reason why I suggest to use checkboxes with the same field name and different export values is just that: when you made a selection with radiobuttons, you can no longer make "no selection", because that is not a legal choice with radiobuttons. With checkboxes, "no selection" is an implicite legal choice, and you can uncheck a choice.
    – Max Wyss
    Oct 30, 2014 at 8:43
  • From the form logic point of view, it would be a good idea to clear sections which have selections, but no number of items. This should be done when a "finalizing" action is executed (such as saving, printing, submitting, etc.). If selections are found, but no quantities, it might be an idea to display an alert to the user, and if he confirms that quantity 0 is correct, to reset the checkboxes/radiobuttons (by setting the field value to "Off".
    – Max Wyss
    Oct 30, 2014 at 8:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.