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;
// 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;