How do I create the calculation to subtract one text box from another?
Copy link to clipboard
Copied
I have a fillable pdf that I need to subtract 2 text boxes in order to get a remaining value. ie: Text12 minus Text17. Formula value would then populate Text18.
Thank you for your help,
Lee
Copy link to clipboard
Copied
You may use built-in features, such as simplified notation in the field where you desired the event or action to take place; "Text18".
See the brief discussion in the link posted below:
Or you may also employ a custom calculation script in the field "Text18".
var a = this.getField("Text12").value;
var b = this.getField("Text17").value;
if (a !=="" || b !=="") {
event.value = a-b;
} else {
event.value ="";
}
The custom script above is just one out of many examples that you can use to obtain the same result.
It may have errors and I haven't tested it on my end (typing from a mobile device).
Copy link to clipboard
Copied
You might want to use && instead of || for this, as if one of the fields is empty the formula will treat it as zero, which is not always correct.
Copy link to clipboard
Copied
Thank you!
Copy link to clipboard
Copied
Thank you for the information. I tried both the Simplified field notation (text12-text17) and (text12-text17=text18) and the custom calculation script coding and both ways give me the options to "cancel" or to "go to...." which then wants a "Line Number:" I don't have a line number. I tried 18, text18, & 7. (the number in the document that has the place for the answer) Nothing seems to work. When I click "ok", nothing happens.
Lee
Copy link to clipboard
Copied
What are the EXACT names of the fields involved?
Copy link to clipboard
Copied
The names of the field are text12 and text17. So - yest - I entered text12-text17 while in the text18 field, but then it wants to go to a line number. How do I know what the Line # is?
Copy link to clipboard
Copied
I am not sure if you're trying to execute the code from the JavaScript console or from the actual target field which should be Text18.
To Use simplified field notation do it like this:
text12-text17
no special characters, remove the parenthesis.
Also, ensure that you are executing this event in the text18 field and that the field names are spelled correctly.
If you decide to use custom calculation script copy the script below and don't change anything that may affect the syntax of the script.
Sometimes, something as minute as using the wrong quote "" types or a different type of font in the JavaScript editor may also affect the script.
var a = this.getField("Text12").value;
var b = this.getField("Text17").value;
if (a !=="" && b !=="") {
event.value = a-b;
} else {
event.value ="";
}
NOTE:
When you open the "Prepare Form" tool, it will allow you to edit text fields objects and other PDF elements, for example.
When you are in this type of edit mode, right-click on the field Text18, and then select from the context menu "Properties".
The "Properties" dialogue window will open up; it has several tabs.
Select the "Calculate" tab. In that tab, you will notice three calculating options.
Tick the radio button next to the feature that you intend to apply.
If you are already familiarized with this and already did it, please share a screenshot of the errors or messages that you see.
Copy link to clipboard
Copied
If the fields are called Text17 and Text12 and you type them in the code (or formula) as text17 and text12 (or vice versa) it won't work, as JS is case-sensitive! You have to make sure to type in the names EXACTLY as they appear in the Fields List. The only exception is the "#1", "#2", etc. notation, which indicates duplicates of the same field name and should not be used when specifying the field name.
Copy link to clipboard
Copied
here is what I see. Yes - I'm familiar with the Properties box and I'm in Text18 to do this. Once I enter the information it then it says GO To ... and there it asks for a line #. I tried Ln1, Col14, but got no where.
Copy link to clipboard
Copied
I think th OK button is not visible because the editor window is shrunk too much.
See if dragging one of the edges and making it bigger do the trick.
If that doesn't resolve the issue, I would say to delete Text18 field, save and close the PDF.
Reopen the PDF and recreate Text18 afresh (just guessing).
Copy link to clipboard
Copied
Forget about the line number text. It's just an indication of where the cursor is. You need to make the window larger by dragging it from the bottom right-hand corner, and then you'll see an OK button appear.
Copy link to clipboard
Copied
WONDERFUL!!! That worked. Now I have to figure out why a grantee can't use it as an auto fill. I know that she is not using any version of Adobe Pro. She uses Adobe reader.
Copy link to clipboard
Copied
This should work just fine in Reader, assuming it's the normal version of Reader and not the mobile one, and that JS is enabled.

