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

HELP - need an include/exlude auto-calculation script for clients order form

jdthomas@compet...
Registered: Dec 2 2011
Posts: 6
Answered

Hey ALL!
 
I created a basic pdf form -- no frills, just a regular order form that calculate quantity, subtotal and total for a client yesterday. I need to calculate sales tax but only for the home state (client is tracking in vs. out of state sales by vol and Amt). I'm fine here. The client wants a checkbox on the sales tax line, I'm fine there as well.
 
What I want is to computer and include value for the sales tax amount if the check box is checked, exclude value and return a zero or null value if it isn't checked so the user doesn't have to. The client is in CA so he needs to include sales tax. The sales tax field is already configured to auto-calc the 8.5% rate (0.085).
 
My problem is the "include/exclude scripts" I've been writing aren't working. I know I'm missing a step, a line or something but I can't figure out what or where. I have the script running in the sales tax (SalesTx) field because that is where the value is calculated or a null value of "zero" is returned, but also other scripts in the checkbox field with a hide/show action control of the SalesTx2/SalesTx fields to display/hide one field with the tax auto-calc'd and the other with a default value of zero (0), and the total field to exclude the SalesTx if hidden.
 
Nothing is working and I'd appreciate the help. This doesnt need to be complex, i just need the SalesTx field to compute the tax if the checkbox is selcted, return a zero value if the checkbox is not selected.
 
Here's the setup, followed by the scripts I've written and tested.
 
Thanks in advance.
 
Setup
Results When: CHECKED | UNCHECKED
Sub Tot: $650.00 | $650.00
CA resident 8.5%[x] 55.25 | [ ] 0.00
S/H: 20.00 | 20.00
TOTAL: $725.25 | $670.00
 
====
Here are the Scripts I've Used:
1st one
checkbox.Checked = (valueInSalesTx = Sub*tax); checkbox.NotChecked = (valueInSalesTx = 0); or
 
2nd one
int valueInSalesTx = 0;
checkbox.Checked = (valueInSalesTx == 0 ? true : false)
   
3rd try:
var one = this.getField("Checkbox18");
var two = this.getField("Sub");
var three = this.getField("tax");
var four = this.getField("SalesTx");
if (one.value == 'Yes') {
two.valueInSalesTx = 'Sub*tax'
} else if (one.value == 'Off') {
two.value='null'
}
  
4th try
var one = this.getField("Checkbox18");
var two = this.getField("Sub");
var three = this.getField("tax");
var four = this.getField("SalesTx");
if (one.value == 'Yes') {
four.value == 'Sub*tax'
} else if (one.value == 'Off') {
four.value='0'
}
  
5th try
var one = this.getField("Checkbox18");
var two = this.getField("SalesTx");
if (one.value == 'Yes') {
two.value == '?'
} else if (one.value == 'Off') {
three.value =='0'
}
 
Last one tried earlier today:
 
var nCheckbox18 = this.getField("Checkbox18");
var nSub = this.getField("sub").value;
if (one.value == 'Yes')
event.value = nSub * 0.085;
else
event.value = 0;
 

My Product Information:
Acrobat Pro Extended 9.0, Windows
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
Accepted Answer
Wow, you've tried a lot. One thing to keep in mind is case matters, so assuming the subtotal field is named "Sub" and the sales tax check box is named "Checkbox18", the custom calculate script for the sales tax field would be:

// Get the field values
var v1 = getField("Checkbox18").value;
var v2 = getField("Sub").value;

// Calculate and set this field's value
if (v1 !== "Off") {
event.value = 0.085 * v2;
} else {
event.value = 0;
}

That last if/else block can be condensed to just:

event.value = v1 !== "Off" ? 0.085 * v2 : 0;
jdthomas@compet...
Registered: Dec 2 2011
Posts: 6
G.J.

Thanks so much for getting back to me, I appreciate it. And it must be the moon or something, but that solutions didn't work either. Just like my scripts, it didn't return any value.

And yes, the script is placed on the Calc tab, under custom calc scrp, and the field is blank and all are Case-Matched:-).

I even entered zero (0) as the default value to get the 0.00 to appear in the SalesTx field and that works in terms of the line not being blank. However, with our without that value entry, the SalesTx does not compute/populate when the checkbox is checked and I am totally thrown by this.

I've been on this two days now, the client has my original form because he needed something today, but I have to figure this out so he can have an auto-calculating form that auto-calcs all everything, not all but one field.

Any ideas? I've recreated the form from scratch a dozen or so times, twice using your solution.

Thnx.
jdthomas@compet...
Registered: Dec 2 2011
Posts: 6
G.J.

Thanks so much for getting back to me, I appreciate it. And it must be the moon or something, but that solutions didn't work either. Just like my scripts, it didn't return any value.

And yes, the script is placed on the Calc tab, under custom calc script in the SalesTx field, and the field still returns blank -- all fields are Case-Matched, and I copy/pasted your script just to make sure there were typos:-).

I even entered zero (0) as the default value to get the 0.00 to appear in the SalesTx field and that works in terms of the line not being blank. However, with or without that value entry, the SalesTx does not compute/populate when the checkbox is checked and I am totally thrown by this.

I've been on this two days now, the client has my original form because he needed something today, but I have to figure this out so he can have an auto-calculating form that auto-calcs all everything, not all but one field.

Any ideas? I've recreated the form from scratch a dozen or so times, twice using your solution.

Thnx.
George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
There's probably something else wrong then. First check that you're not getting any errors form some other part of your form by checking the JavaScript console. Show it by pressing the Ctrl+J combination.

If you don't see any errors, make sure the field calculation order is correct. Do do this go into form editing mode (Forms -- Add or Edit Fields), and then "Forms -- Edit Fields -- Set Field Calculation Order" and set it to what makes sense for your form.

Calculated fields should be set to read-only and the calculate script only trigger when another field value is changed.

If none of these things helps, post the form somewhere so we can take a look.
jdthomas@compet...
Registered: Dec 2 2011
Posts: 6
Interesting you mention that, the consol ouput says:

getField("Checkbox18") has no properties
2:Field:Calculate

I'd rather email than post for your comments, if you don't mind, send me your email address.

Thanks,
Jerri

George_Johnson
Expert
Registered: Jul 6 2008
Posts: 1875
What that means is there is not a field with that exact name. Double-check the name of the check box, making sure there are no leading or trailing spaces. That should fix it, but if not, post again.
jdthomas@compet...
Registered: Dec 2 2011
Posts: 6
BINGO, that was it actually, the default system generated name "Check Box" has a space between it so it was two words. In proofing based upon your suggestion I started with the system generated label and voila that's when I noticed it. Once I joined them into one word, the SalesTx field auto populated.

Its always something hidding in plain sight!

Thank you, thank you, thank you.

Have a good one!