Copy link to clipboard
Copied
I am currently using Acrobat to create a fillable form. Basically I want the selection from the drop down of provinces to calculate the taxes from the SubShip field. I have 3 text fields labelled GST, HST and PST, and the selection should fill out each box respectively. However, with the code I am using now, it is only calculating 13% of the SubShip field no matter which province is selected, and it is only showing in the HST box. Below is my code, and I have no idea where I am going wrong.
Can someone please help?!?!
var sNewSel = event.value;
switch (sNewSel) {
case "Ontario":
this.getField("HST").value = (this.getField(Subtotal).value +
this.getField(Shipping).value) * this.getField("0.13").value;
this.getField("PST").value = "0";
this.getField("GST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Prince Edward Island":
this.getField("HST").value = this.getField(SubShip).value * this.getField("0.14").value;
this.getField("PST").value = "0";
this.getField("GST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Alberta":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
this.getField("PST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "British Columbia":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("PST").value = this.getField(SubShip).value * this.getField("0.07").value;
this.getField("HST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Manitoba":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("PST").value = this.getField(SubShip).value * this.getField("0.08").value;
this.getField("HST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "New Brunswick":
this.getField("HST").value = this.getField(SubShip).value * this.getField("0.13").value;
this.getField("GST").value = "0";
this.getField("PST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Nova Scotia":
this.getField("HST").value = this.getField(SubShip).value * this.getField("0.15").value;
this.getField("GST").value = "0";
this.getField("PST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Nunavut":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
this.getField("PST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Quebec":
this.getField("PST").value = this.getField(SubShip).value * this.getField("0.9975").value;
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Saskatchewan":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("PST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Yukon":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
this.getField("PST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Newfoundland":
this.getField("HST").value = this.getField(SubShip).value * this.getField("0.13").value;
this.getField("GST").value = "0";
this.getField("PST").value = "0";
break;
}
var sNewSel = event.value;
switch (sNewSel) {
case "Northwest Territories":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
this.getField("PST").value = "0";
break;
}
Your link does not allow access to the file.
You error means there is an error in the field name being used in the script. You need to very carefully check the spelling and capitalization of the field name.
Copy link to clipboard
Copied
Have you looked at the MDN JavaScript Reference for the switch statement?
I have never seen it coded as you have. Do you get any errors with your code?
I would code it something like this:
switch (event.value) {
case "Ontario":
this.getField("HST").value = (this.getField(Subtotal).value +
this.getField(Shipping).value) * this.getField("0.13").value;
this.getField("PST").value = "0";
this.getField("GST").value = "0";
break;
case "Prince Edward Island":
this.getField("HST").value = this.getField(SubShip).value * this.getField("0.14").value;
this.getField("PST").value = "0";
this.getField("GST").value = "0";
break;
case "British Columbia":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("PST").value = this.getField(SubShip).value * this.getField("0.07").value;
this.getField("HST").value = "0";
break;
case "Manitoba":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("PST").value = this.getField(SubShip).value * this.getField("0.08").value;
this.getField("HST").value = "0";
break;
case "New Brunswick":
this.getField("HST").value = this.getField(SubShip).value * this.getField("0.13").value;
this.getField("GST").value = "0";
this.getField("PST").value = "0";
break;
case "Nova Scotia":
this.getField("HST").value = this.getField(SubShip).value * this.getField("0.15").value;
this.getField("GST").value = "0";
this.getField("PST").value = "0";
break;
case "Nunavut":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
this.getField("PST").value = "0";
break;
case "Quebec":
this.getField("PST").value = this.getField(SubShip).value * this.getField("0.9975").value;
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
break;
case "Saskatchewan":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("PST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
break;
case "Yukon":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
this.getField("PST").value = "0";
break;
case "Newfoundland":
this.getField("HST").value = this.getField(SubShip).value * this.getField("0.13").value;
this.getField("GST").value = "0";
this.getField("PST").value = "0";
break;
case "Northwest Territories":
this.getField("GST").value = this.getField(SubShip).value * this.getField("0.05").value;
this.getField("HST").value = "0";
this.getField("PST").value = "0";
break;
default:
// when no match found;
this.getField("GST").value = 0;
this.getField("HST").value = "0";
this.getField("PST").value = "0";
break;
} // end province switch;
Copy link to clipboard
Copied
Hey so I used this code, and its working much better, the only thing is that it is still calculating the tax based off of the field named "subtotal" not the "SubShip" field. Any ideas?!
Thank you so so so much!!!!!
Copy link to clipboard
Copied
Actually, I just checked and it only works for ontario still, but the 0's in the other boxes are there now!
Copy link to clipboard
Copied
Our crystal ball links are down, we cannot see your form. You should post a link to the form so others can see your form and all the coding you have applied to it.
Have you opened the Acrobat JavaScript console to see if you have any errors?
It looks like you are using the shipping rate value as field names.
Copy link to clipboard
Copied
Here it is! I put the code in the action for the province, GST, HST, PST!
https://cloud.acrobat.com/file/107ff61c-611a-470f-b0de-98af8dcb5d5d
Copy link to clipboard
Copied
Your link may work for you but not for me.
Copy link to clipboard
Copied
2015 Fillable.pdf - Google Drive
This link should work!
Copy link to clipboard
Copied
Go to Edit - Preferences - JavaScript and tick the box that says "Show console on errors and warnings". Then open your file...
Copy link to clipboard
Copied
Try this script:
switch (event.value) {
case "Ontario":
this.getField("HST").value = (this.getField("Subtotal").value +
this.getField(Shipping).value) * 0.13;
this.getField("PST").value = 0;
this.getField("GST").value = 0;
break;
case "Prince Edward Island":
this.getField("HST").value = 0.14;
this.getField("PST").value = 0;
this.getField("GST").value = 0;
break;
case "British Columbia":
this.getField("GST").value = this.getField("SubShip").value * 0.05;
this.getField("PST").value = this.getField("SubShip").value * 0.07;
this.getField("HST").value = 0;
break;
case "Manitoba":
this.getField("GST").value = this.getField("SubShip").value * 0.05;
this.getField("PST").value = this.getField("SubShip").value * 0.08;
this.getField("HST").value = 0;
break;
case "New Brunswick":
this.getField("HST").value = this.getField("SubShip").value * 0.13;
this.getField("GST").value = 0;
this.getField("PST").value = 0;
break;
case "Nova Scotia":
this.getField("HST").value = this.getField("SubShip").value * 0.15;
this.getField("GST").value = 0;
this.getField("PST").value = 0;
break;
case "Nunavut":
this.getField("GST").value = this.getField("SubShip").value * 0.05;
this.getField("HST").value = 0;
this.getField("PST").value = 0;
break;
case "Quebec":
this.getField("PST").value = this.getField("SubShip").value * 0.9975;
this.getField("GST").value = this.getField("SubShip").value * 0.05;
this.getField("HST").value = 0;
break;
case "Saskatchewan":
this.getField("GST").value = this.getField("SubShip").value * 0.05;
this.getField("PST").value = this.getField("SubShip").value * 0.05;
this.getField("HST").value = 0;
break;
case "Yukon":
this.getField("GST").value = this.getField("SubShip").value * 0.05;
this.getField("HST").value = 0;
this.getField("PST").value = 0;
break;
case "Newfoundland":
this.getField("HST").value = this.getField("SubShip").value * 0.13;
this.getField("GST").value = 0;
this.getField("PST").value = 0;
break;
case "Northwest Territories":
this.getField("GST").value = this.getField("SubShip").value * 0.05;
this.getField("HST").value = 0;
this.getField("PST").value = 0;
break;
default:
// when no match found;
this.getField("GST").value = 0;
this.getField("HST").value = 0;
this.getField("PST").value = 0;
break;
} // end province switch;
Copy link to clipboard
Copied
It's still only calculating from the subtotal box, and nothing comes up in the GST and PST boxes! Coding is so awful, I appreciate your help!
Copy link to clipboard
Copied
I don't see any code in the field "Province".
Copy link to clipboard
Copied
I put it as an action on blur!
Copy link to clipboard
Copied
This script is in lots of places that are never activated.
I would not place this script within the Provence field since this field would be completed prior to the selections for the purchase. It might work in the custom calculation script and then one needs to make sure the field calculation order is correct.
Pieces of this could be placed in the various fields being computed.
This form might be a good candidate for one large script to be used to calculate the entire form.
Have you checked your form for other errors?
You might want to work this out on a much simpler version of the form.
Copy link to clipboard
Copied
So I made a new simple form and I get the error "TypeError: this.getField("SubShip") is null 13:Field:Blur
I googled what that meant but I have no idea how to fix it! Heres a link to the file:https://drive.google.com/open?id=0B6mbO045-Rq9LTFWMS1Jc2RTUXM
Copy link to clipboard
Copied
Your link does not allow access to the file.
You error means there is an error in the field name being used in the script. You need to very carefully check the spelling and capitalization of the field name.
Copy link to clipboard
Copied
FormTest.pdf - Google Drive​
Sorry, my bad!
I've gotten everything to work except Ontario, the HST just comes up as NaN, but PEI, Manitoba, and Alberta work!
Copy link to clipboard
Copied
Change this line in your code:
this.getField("HST").value = this.getField("SubShip") * 0.13;
To this:
this.getField("HST").value = this.getField("SubShip").value * 0.13;
Copy link to clipboard
Copied
Thank you so much!!!!
Find more inspiration, events, and resources on the new Adobe Community
Explore Now