Copy link to clipboard
Copied
My knowledge of Javascript is very basic and I have a pdf form I cannot figure out the javascript.
I need to calculate taxes based on which checkbox is checked.
If checkbox 1 is checked, then need to calculate Federal tax (5%) on the "total", if checkbox 2 is checked then the value is 0, if checkbox3 is checked then a manual entry is to be made
Copy link to clipboard
Copied
For this you definately need a script.
Are these "checkboxes" mutually exclusive? i.e radio buttons. Or are they completely different checkboxes?
So here's a script that assumes the "checkboxes" are really radio buttons named "TaxType", with export values of "Choice1", "Choice2","Choice3".
This script goes into the custom calculation on Tax field.
var nTotal = Number(this.getField("Total").value);
var nChoice = this.getField("TaxType").value;
// block manual entry
event.target.readonly = true;
switch(nChoice)
{
case "Choice1":
event.value = .05 * nTotal;
break;
case "Choice2":
event.value = 0;
break;
case "Choice3":
event.rc = false; // This allows for manual entry
event.target.readonly = false;
break;
default:
event.value = "";
break;
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
For this you definately need a script.
Are these "checkboxes" mutually exclusive? i.e radio buttons. Or are they completely different checkboxes?
So here's a script that assumes the "checkboxes" are really radio buttons named "TaxType", with export values of "Choice1", "Choice2","Choice3".
This script goes into the custom calculation on Tax field.
var nTotal = Number(this.getField("Total").value);
var nChoice = this.getField("TaxType").value;
// block manual entry
event.target.readonly = true;
switch(nChoice)
{
case "Choice1":
event.value = .05 * nTotal;
break;
case "Choice2":
event.value = 0;
break;
case "Choice3":
event.rc = false; // This allows for manual entry
event.target.readonly = false;
break;
default:
event.value = "";
break;
}
Use the Acrobat JavaScript Reference early and often
Copy link to clipboard
Copied
it works perfectly. Thank you so much
Copy link to clipboard
Copied
On the same document, I am trying to calculate a percentage (GP%). My script is very simple: Margin/Total. However, the form user will get an error message "The value entered does not match the format of the field (GP). The user can bypass by clicking OK but this is not ideal. I understand that the error message happens when the value is 0 but I do not know how to fix that
Copy link to clipboard
Copied
A common issue. Here's an article on the topic:
https://www.pdfscripting.com/public/Value-Entered-Does-Not-Match-Format.cfm?sd=40
Use the Acrobat JavaScript Reference early and often

