Skip to main content
nigels9669949
Participant
March 29, 2025
Question

Auto calculate field when check box is ticked.

  • March 29, 2025
  • 2 replies
  • 976 views

Hoping someone can help with what I'm sure is a very basic function (probably hundreds of threads already written, just can't find them).

 

So I have a [text field] that calculates a 10% GST value [GST Value] based on a value in a preceding text box [Total Value]. This works fine, and the script for this looks like this:

 

event.value = Number(this.getField("Total Value").valueAsString) / 11;

 

However, I only want this calculation to run (show) if a check box is ticked [GST Check Box]. How do I go about this?

 

2 replies

PDF Automation Station
Community Expert
Community Expert
March 30, 2025

How do you get 10% by dividing by 11?

Nesa Nurani
Community Expert
Community Expert
March 30, 2025

@PDF Automation Station 

When a price includes GST, it means the total price is made up of 100% (original value) + 10% GST.

So, the total price represents 110% of the original amount (or 1.1 times the original price) so when divided by 11 you get 10%.

PDF Automation Station
Community Expert
Community Expert
March 30, 2025

The way it's worded, I thought the calculation was 10% GST on the total (* 0.1), not 10% on the total + the tax.

try67
Community Expert
Community Expert
March 29, 2025

if (this.getField("GST Check Box").valueAsString=="Off") event.value = "";
else event.value = Number(this.getField("Total Value").valueAsString) / 11;

nigels9669949
Participant
March 31, 2025

Perfect, thanks so much for this, worked a treat.

 

Had another thought and wondered if you might know the answer to this (if I can explain it will enough).

 

So, on the above setup, when the [GST Check Box] is ticked, the GST amount is calculated and appears in a [GST] field. This works well when the user 'remembers' to check the [GST Check Box] when it's applicable. In our case GST is only applicable when a buyer is from Australia. So, is there a way to trigger the GST calculation, not when the [GST Check Box] is ticked, but rather when the user enters the country 'Australia' in the address box (FYI, I have a separate text field for 'Country')?

Hope that explanation makes sense.

 

One other question. In the address details, Country is a text field, I'd like to have a Country dropdown field, but I don't want to manually add each country. Is there a way to paste a full list of countries into this dropdown?

 

Both these questions are a 'nice to have' but not critical to the functioning of the doc.

 

Nesa Nurani
Community Expert
Community Expert
March 31, 2025

To populate a dropdown with country names, create a dropdown field and name it "Country", and run this script from console or a button:

var countryList = ["-Select Country-",
    "Afghanistan", "Albania", "Algeria", "Andorra", "Angola", "Antigua and Barbuda", "Argentina", "Armenia", "Australia", "Austria",
    "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bhutan",
    "Bolivia", "Bosnia and Herzegovina", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia",
    "Cameroon", "Canada", "Central African Republic", "Chad", "Chile", "China", "Colombia", "Comoros", "Congo (Congo-Brazzaville)", "Costa Rica",
    "Croatia", "Cuba", "Cyprus", "Czechia", "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominica", "Dominican Republic", "Ecuador",
    "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini (Swaziland)", "Ethiopia", "Fiji", "Finland", "France",
    "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Greece", "Grenada", "Guatemala", "Guinea", "Guinea-Bissau",
    "Guyana", "Haiti", "Honduras", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland",
    "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kuwait", "Kyrgyzstan",
    "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Madagascar",
    "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Mauritania", "Mauritius", "Mexico", "Micronesia",
    "Moldova", "Monaco", "Mongolia", "Montenegro", "Morocco", "Mozambique", "Myanmar (Burma)", "Namibia", "Nauru", "Nepal",
    "Netherlands", "New Zealand", "Nicaragua", "Niger", "Nigeria", "North Korea", "North Macedonia", "Norway", "Oman", "Pakistan",
    "Palau", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Poland", "Portugal", "Qatar", "Romania",
    "Russia", "Rwanda", "Saint Kitts and Nevis", "Saint Lucia", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal",
    "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Korea",
    "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Sweden", "Switzerland", "Syria", "Taiwan", "Tajikistan",
    "Tanzania", "Thailand", "Timor-Leste", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkey", "Turkmenistan", "Tuvalu",
    "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "Uruguay", "Uzbekistan", "Vanuatu", "Vatican City", "Venezuela",
    "Vietnam", "Yemen", "Zambia", "Zimbabwe"
];

var dropdown = this.getField("Country");
dropdown.setItems(countryList);

You can then use this to calculate GST:

if (this.getField("Country").valueAsString !== "Australia") 
 event.value = "";
else 
 event.value = Number(this.getField("Total Value").valueAsString) / 11;