Skip to main content
Participating Frequently
July 15, 2016
Answered

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

  • July 15, 2016
  • 1 reply
  • 2339 views

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;

}

This topic has been closed for replies.
Correct answer gkaiseril

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


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.

1 reply

Inspiring
July 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;

Participating Frequently
July 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!!!!!