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

Form Calculations

Chris Lunt
Registered: Aug 22 2011
Posts: 17
Answered

Hi, started using Acrobat and tried to learn how to make forms for the first time yesterday.
Really sorry, these questions are bound to have been covered but I did spend a good 2 hours searching the forums and whereas I learnt a lot, I just couldn't seem to get my syntax correct for a problem I have with a form calculation.
 
I have 2 queries, the first probably a very easy one.
 
1)
I have a text field called MLS1, users of the form can fill in the value but let's say they enter 100.
I have another field called MLSBox which is a checkbox.
I have a another text field called MLSTotal.
I want the ticking of the checkbox to enter the value from the MLS1 field into the MLSTotal box.
So if the MLS1 field says 100, and the checkbox is checked, the MLSTotal box should also say 100.
Also if the checkbox is unchecked, I want the MLSTotal box to say 0.
 
I've come close to making this work but not quite there and my brain can't take any more! Part of my confusion lies in whether I'm meant to be writing the script in the MLSBox or MLSTotal fields.
 
2)
A bit more complex, probably?
I have a text field called IDK1
I have a drop down menu field numbered 0-8 called IDKBox
I have a text field called IDKTotal
 
Don't know where to even begin on this one.
I want it to be the case that if I select '1' from the drop down menu, the value from field IDK1 is copied into IDKTotal.
However, when numbers 2-8 are selected, it needs to add 75 each time to the value in IDKTotal, rather than take the product from IDK1 and multiply it by the IDKBox value.
So if IDK1 says 200, I want it to be the case that by selecting '1' from the drop down, 200 is entered into IDKTotal.
But if '2' is selected, I want IDKTotal to say 275, '3' to say '350' etc.
And again, if '0' is selected, IDKTotal to say 0.
Is that possible at all?
 
Incidentally I'm using Acrobat X Pro.
 
Thank you very much in advance for any assistance you can provide!

My Product Information:
Acrobat Pro 10.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
1. If you don't want MLSTotal to be editable, then set it as read-only and place the script there (as its custom calculation script). You can use something like this:

if (getField("MLSBox").value=="Yes") // if the check-box is ticked
event.value = getField("MLS1").value; // ...copy the value of MLS1
else event.value = "0"; // otherwise, reset this field.

2. You can use something like this as the custom-calculation script of IDKTotal:
event.value = Number(getField("IDK1").value) * Number(getField("IDKBox").value);

This is enough because if "0" is selected, the result will be 0. If "1" is selected, the result is the value of IDK1, etc.
We just need to convert the values to real numbers, which is what the Number() function does.

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Chris Lunt
Registered: Aug 22 2011
Posts: 17
Accepted Answer
Oh brill, thanks a bunch, for the first issue I just couldn't seem to find the correct syntax to write this so that it works... I was quite close!

As for the second issue, I don't think that quite works because it will still multiply the value of IDK1 by the number in the IDKBox which isn't exactly what I'm after.

This is how it would look in a table:

IDK1* IDKBox IDKTotal
200 0 0
200 1 200
200 2 275
200 3 350
etc...

As it goes I don't have a field for the 75 increment anywhere, if it's necessary I can add it unless I can just multiply by 75 in the script.
I think I'll need to do something similar to what you've written, but for it say if IDKBox = 0, return 0, if IDKBox = 1, return 200 and if IDKBox = 2-8, return 200 plus IDKBox * 75
In excel I'd probably have some sort of nested "IF" formula to achieve this, but I'm not sure how that works in this situation
try67
Expert
Registered: Oct 30 2008
Posts: 2398
Is the formula for #2: IDK1 + ((IDKBox-1) * 75)
(except if IDKBox = 0) ?

If so, use this code:
var idk1 = Number(getField("IDK1").value);
var idkbox = Number(getField("IDKBox").value);
if (isNaN(idk1) || idk1==0) event.value = 0;
else event.value = idk1 + ((idkbox-1)*75);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

Chris Lunt
Registered: Aug 22 2011
Posts: 17
Wow that works perfectly, thank you so much for your help here, it would have taken many more hours for me to have ever worked this out, very much appreciated!