These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Javascript Calculation - variables

Ada01
Registered: Jan 28 2009
Posts: 14

I have been racking my brain on this for a while, with noting more than a sore brain.

I am creating a user form for designing a product and creating a self-estimate based on components. I sell in sets of 25 and each piece has it's own cost per 25. Each piece can be produced in two ways (A or B process). I have a drop-down field for the Process to be used and another for the qty in intervals of 25.

Example:

Product 57 = $50 (A) or $65 (B) per 25
Order = 100
Process chosen = A
Flat Rate = $125

so the calculation should be: =((100/25)*52)+125 = 325

I cannot do this for the life of me! I can in Excel, this i am able to do, however for universality i need to use a PDF. my research says a custom javascript calculation is needed:

assume that drop-down for process is called Process 57 and the Qty drop-down is qty 57

Any direction would be greatly appreciated.

Thanks

My Product Information:
Acrobat Pro 9.3.1, Macintosh
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Have you looked at the tutorials, eSeminars on demand dealing with calculations?

Have you looked at the references for Acrobat JavaScript and Mozilla JavaScript?

JavaScript is object orientated and requires one to establish an association to an object like a named field and then use either a property, like value, of that object or a method of that object.

From your text and supplied values, it is not very clear how your computation works. But I will make the following guess:

George Kaiser

Ada01
Registered: Jan 28 2009
Posts: 14
I am a VBA guy, so i can handle the "object oriented" portion...i think it is the language...i will tweak the language and make sure that is am not missing one of the nuances .value or something and get back when the road block is sufficiently stopping me.

Thanks
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
It appears you have a product that can be created by one to two processes, A or B. The cost for each process is $50 for 25 items created by the A process and $65 for 25 items created by the process. There is also a flat setup fee of $125.

So if one selects process A and a quantity of 100, the number of sets needed to be produced is 4 or 100 / 25. The cost per 25 items for process A is $50 or $200 for the ordered quantity. and the setup fee of $125 results in a total cost of $325. The calculation with the number is ((100 / 25) * 50) + 125 = 325.

Assuming you have the following fields:

Combo box named 'Process' with choices of 'A' and 'B'. The export value for 'A' is 50 and the export value for 'B' is 65.

Combo box named 'Quantity' with various number in increments of 25 from 0 to 300 with an export value of the displayed quantity divided by 4. This just simplifies the computation.

Text field named 'Total' with a format of number with 2 decimal places, the monetary unit is optional.

You can then have a 'Simplified field notation' script of:
Process * Quantity + 125
If you want to use the 'Custom calculation script' the code becomes:
var nProcess = this.getField('Process').value;var nQuantity = this.getField('Quantity').value;event.value = (nProcess * nQuantity) + 125;

George Kaiser

Ada01
Registered: Jan 28 2009
Posts: 14
gkaiseril wrote:
You can then have a 'Simplified field notation' script of:
Process * Quantity + 125
If you want to use the 'Custom calculation script' the code becomes:
var nProcess = this.getField('Process').value;var nQuantity = this.getField('Quantity').value;event.value = (nProcess * nQuantity) + 125;
the" ' " ('Process').value is what I was missing...it will not compile without this?

Thanks

I think I may want to go a little more in depth to really define things (so as to only give a total when all fields are used) + if it is custom I apply one set up fee and if it is a re-run there is another...now that i have the idea, i may be able to figure the rest.