Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trying to make a drop down selection automatically calculate another field, but it is only caclulating one drop down selection

New Here ,
Jul 15, 2016 Jul 15, 2016

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;

}

TOPICS
Acrobat SDK and JavaScript
2.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 03, 2016 Aug 03, 2016

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.

Translate
LEGEND ,
Jul 15, 2016 Jul 15, 2016

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2016 Jul 15, 2016

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!!!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 15, 2016 Jul 15, 2016

Actually, I just checked and it only works for ontario still, but the 0's in the other boxes are there now!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 15, 2016 Jul 15, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2016 Jul 18, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 18, 2016 Jul 18, 2016

Your link may work for you but not for me.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 18, 2016 Jul 18, 2016

2015 Fillable.pdf - Google Drive

This link should work!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 18, 2016 Jul 18, 2016

Go to Edit - Preferences - JavaScript and tick the box that says "Show console on errors and warnings". Then open your file...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 18, 2016 Jul 18, 2016

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 21, 2016 Jul 21, 2016

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 22, 2016 Jul 22, 2016

I don't see any code in the field "Province".

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 25, 2016 Jul 25, 2016

I put it as an action on blur!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 25, 2016 Jul 25, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 03, 2016 Aug 03, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 03, 2016 Aug 03, 2016

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 04, 2016 Aug 04, 2016

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 04, 2016 Aug 04, 2016

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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 04, 2016 Aug 04, 2016
LATEST

Thank you so much!!!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines