Copy link to clipboard
Copied
I have a form that I have created that is suppose to act like a receipt, where it mulitplies the quantity by the cost and puts it in each row and at then end adds all rows and taxes and shipping to get grand total, but I have been asked is there a way to take the taxes out on some occassions. If buying from Amazon there are no taxes. So I decided to try to make a check box for taxes necessary or not and then add them in if the box was check yes or not. I can not get the script correct to make the taxes be optional based off the check box. Help!!! Please!
Copy link to clipboard
Copied
You're nearly there. Let's say the check-box is called "AddTax". You can then use this code as the custom calculation script of your grand total field:
// set the tax rate to 7.25%
var tax_rate = 0.0725;
// Get the value of the subtotal field
var subtotal = Number(this.getField("Subtotal").valueAsString);
if (this.getField("AddTax").valueAsString=="Off")
event.value = subtotal;
else event.value = subtotal * (1+tax_rate);
Copy link to clipboard
Copied
Hi,
Nope, no need to mess with the checkbox , just place this script as the custom calculation script of the text field where you want the subtotal to be displayed when the user ticks the checkbox.
And dont forget to add Try67 script as the custom calculation script in another field to display the grand total
Copy link to clipboard
Copied
Hi,
Do you mind sharing the code that you have tried so far?
Copy link to clipboard
Copied
I am not sure where to start to get it based off a check box. i have it now where it will do the taxes all the time.
// set the tax rate to 7.25%
var tax_rate = 0.0725;
// Get the value of the subtotal field
var subtotal = getField("Subtotal").value;
// Set this field value
{event.value = subtotal * tax_rate;
}
Copy link to clipboard
Copied
For this to work in the easiest manner you need to use a two checkboxes or two radio buttons.
You have to name both checkboxes with the same field name; then in the Checkbox Properties, Options tab, put in the export value 0.0725 and in the other checkbox put 1 as the export value and tick in this one "Checkbox is checked by default" and leave this unticked in the other checkbox that has the export value of the tax rate.
Then in the text field where you want to calculate this tax, place your code in custom calculation script like this:
var a = this.getField("Subtotal").value;
var b = this.getField("tax_rate").value; //this is your checkbox field name
event.value = a*b;
Copy link to clipboard
Copied
I apologize I made a mistake and you don't need two checkboxes. You only need one checkbox and leave unticked the option "Checkbox is checked by default".
Also, you don't need to assign an export value in the checkbox as long you use this script in your subtotal field as custom calculation script:
var a = this.getField("subtotal").valueAsString;
var b = this.getField("tax_rate").value.toString().replace(/Off/gim, "0")*1 ;
var c = this.getField("tax_rate").value.toString().replace(/Off/gim, "0")*.0725 ;
var d = this.getField("subtotal").value*this.getField("tax_rate").value;
if (b==1) event.value = "";
else if(b=="") event.value ="";
else if(a=="") event.value ="";
else {event.value = d;}
Copy link to clipboard
Copied
You're nearly there. Let's say the check-box is called "AddTax". You can then use this code as the custom calculation script of your grand total field:
// set the tax rate to 7.25%
var tax_rate = 0.0725;
// Get the value of the subtotal field
var subtotal = Number(this.getField("Subtotal").valueAsString);
if (this.getField("AddTax").valueAsString=="Off")
event.value = subtotal;
else event.value = subtotal * (1+tax_rate);
Copy link to clipboard
Copied
Thank you Try67!
I was going crazy with the NaN error message until I came accross this link : https://answers.acrobatusers.com/How-to-get-rid-of-Warning-q264336.aspx
Copy link to clipboard
Copied
Is there a setting on the radio button check box that I need to make sure I have clicked? I have used this script below and added the check box No Sales Taxes?
var a = this.getField("Subtotal").valueAsString;
var b = this.getField("No Sales Taxes").value.toString().replace(/Off/gim, "0")*1 ;
var c = this.getField("No Sales Taxes").value.toString().replace(/Off/gim, "0")*.0725 ;
var d = this.getField("subtotal").value*this.getField("tax_rate").value;
if (b==1) event.value = "";
else if(b=="") event.value ="";
else if(a=="") event.value ="";
else {event.value = d;}
Copy link to clipboard
Copied
Check the console for errors.
Copy link to clipboard
Copied
The value of "b" can't be "" if you multiply it by 1...
Copy link to clipboard
Copied
Yes sorry i didn't remove that line when I was trying to use two checkboxes in the earlier reply.
Thanks!
Copy link to clipboard
Copied
I suggested earlier about the raduo buttons and checkboxes to be used in pairs.
However, this script that you are using I was able to test it using it as the custom calculation script of a single checkbox.
That way you can check and uncheck the checkbox to apply the tax , and if the user uncheck it you won't get the NaN error.
On the other hand if you still choose to use radio buttons the don't provide the ability to be ticked or unticked unless you use it in pairs in which case you will have to use to name both radio buttons with the same field name and but assigning them different export values to make them mutually exclusive when selected or unselected.
Copy link to clipboard
Copied
Alrighty!! i am trying to finish this one today! The code i have is below. it is on the Sales Taxes cell in the form. Do i need code as well on the check box to make them work together? I can not get it to calculate the .0725 taxes without manually entering them in the taxes box. Just wanted to check. I am not and expert at reading what is going to happen in the code.
var a = this.getField("Subtotal").valueAsString;
var b = this.getField("No Sales Taxes").value.toString().replace(/Off/gim, "0")*1 ;
var c = this.getField("No Sales Taxes").value.toString().replace(/Off/gim, "0")*.0725 ;
var d = this.getField("subtotal").value*this.getField("tax_rate").value;
if (b==1) event.value = "";
else if(a=="") event.value ="";
else {event.value = d;}
Copy link to clipboard
Copied
Hi,
Nope, no need to mess with the checkbox , just place this script as the custom calculation script of the text field where you want the subtotal to be displayed when the user ticks the checkbox.
And dont forget to add Try67 script as the custom calculation script in another field to display the grand total