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

Simple If calculation

lisamwise
Registered: May 18 2009
Posts: 22
Answered

I have a form where I would like to automatically calculate the sales tax on the subtotal based on if the billing state entered is Iowa. I have tried a few simple if statements in the custom calculation scripts section, but none have worked.

Here's one I have tried:

var state = this.getField("B_state").value;
var subt = this.getField("Subtotal").value;
var rate = subt * .07;
if (state == "ia") event.value = rate;
else event.value = 0;

Can anyone help me with this? I am a total javascript newbie and got the examples above from reading other threads on this forum. Thanks!

My Product Information:
Acrobat Pro 8.1.2, Windows
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
Did you get any errors in the JavaScript debugging console?

Are you creating the form in Acrobat or LiveCycle Designer?

What are the possible export values for the "B_state" field?

For a field that holds the sales tax rate, and the export values for the 'B_stae' field are the standard U.S. Postal 2 letter state values:
event.value = 0; // assume no sales taxvar state = this.getField("B_state").value.toLowerCase();if (state == "ia")  event.value = 0.07;

Once you get the sales tax rate field to work, you can then compute the sales tax amount and total of the sales tax and subtotal.

George Kaiser

lisamwise
Registered: May 18 2009
Posts: 22
Thanks for your reply gkaiseril! I didn't even think of using a separate field for the sales tax rate itself. That would definitely be the way to do it if we charged different rates based on the state, but we only charge for orders from Iowa. My formula above would have worked if had double-checked the name of the State field! It was "B_State" instead of "B_state". Fixed this problem and it worked.
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
From a tax reporting view point, it is always better to state the sales tax as a seperate entry on a sales slip.

George Kaiser

lisamwise
Registered: May 18 2009
Posts: 22
That's a good point. I will definitely use that on any forms that go out to customers, but this is an internal form that we are having it calculate the sales tax because of past user errors.

I had to use LifeCycle Designer to finalize this form because we are converting credit card numbers to bar codes, but now the sales tax script doesn't work. When I imported the pdf into LiveCycle it said that the javascript that needs to be updated will be commented out. Sure enough, my script for the sales tax was gone. When I try to put it back in, it doesn't work.

Here's what I had in the Sales Tax field that calculated the sales tax if the customer's state was IA:
var state = this.getField("State").value.toLowerCase();var subt = this.getField("Subtotal").value;var rate = subt * .07;if (state == "ia") event.value = rate;else event.value = 0;