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

How to use radio buttons to choose which calculations run

New Here ,
Aug 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

I am attempting to create a form for our seedling tree order form, and am running into a little trouble with calculating the proper total, as our taxation rates vary depending upon the method of shipment being used.  I believe my end result can be created with a little help from a custom calculation script, but I have no experience with java script, and am hopeful that someone can give me an assist here.

Already set up, I have:

Two radio buttons used to indicate the method of distribution desired
-Local Pick Up
-UPS Shipping

I have two hidden fields, in which calculations are run to figure the two tax values, one of which should be applied. (LocTax) and (UPSTax)


I have fields to calculate the total cost for shipping (Ship Tot), for the sub total of items ordered (Item Tot), a placeholder for the tax rate (Tax Tot), and a Final Order Total (Order Tot) field, in which the sub total, shipping costs, and tax rate are added, and the final total displayed.

My problem is with this last section, as in order to properly calculate and display the total cost for an order, the proper tax value needs to be used.

I’d like for the value of the placeholder (Tax Tot) to be filled based upon the radio button selected.

So,

If Local Pick Up is selected, then the Tax Tot field should be populated with the value from the hidden LocTax field.
If UPS Shipping is selected, then the Tax Tot should populate with the value from the hidden UPSTax field.

I’m reasonably certain that a script could be written to do this, possibly even in such a way as to negate the need for my hidden fields, but I have no experience with javascript and am not sure how to write this.

I’d appreciate any assistance anyone could offer in how to do this, especially as I may need to further complicate it by adding one more variable, a tax exempt button, which would negate either of the above choices if selected.

Many thanks!!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

843

Translate

Translate

Report

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 09, 2018 Aug 09, 2018

Copy link to clipboard

Copied

Here's and article with a sample that provides most of the solution you need:

https://acrobatusers.com/tutorials/conditional-execution

Here are some general articles on scripting calculations:

Calculating field values and more

https://acrobatusers.com/tutorials/how-to-do-not-so-simple-form-calculations

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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 ,
Sep 13, 2018 Sep 13, 2018

Copy link to clipboard

Copied

Thom,

Thanks for those suggestions.

I've bookmarked the links and will make my way through them as time allows.  My biggest issue with any of this however is that I lack the code writing experience, and don't know the proper syntax to utilize in writing what I need.

I could write a simple paragraph, using an if/then type statement to illustrate what I want, but I don't know how to translate that into the proper code to insert into the document.  Any suggestions on that?

(I have a set of radio buttons titled ShipMeth, with two options (UPS Ship or PickUp))

So, what I want to say is:

If - ShipMeth is checked for UPS Ship

then fill the field titled TaxTot with the value from field UPSTax

If - ShipMeth is checked for Pickup

then fill the field titled TaxTot with the value from field LocTax

The third, curveball option would simply be a third option for the radio buttons for tax exemption, which would mean another button, with an if/then of If TaxExempt = checked, then Fill TaxTot field with 0

If I can get these couple things to function, I've got all the other calculations working as I need.

It might not be the most elegant way of setting this up, but it accomplished what we need, provided I can get this variable tax rate thing figured out.

Is there a tutorial you can point me towards that would help me learn the proper 'language' to use when writing these scripts, or can you help me out with a quick lesson on how to make this work?

Votes

Translate

Translate

Report

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 ,
Sep 18, 2018 Sep 18, 2018

Copy link to clipboard

Copied

The article and web site I linked in my previous post are exactly what you are asking for, and the sample file at the first link provides the code for most of what you requested.

The code provided by MatLac is close but has some errors. Here is a rewrite of the code that will work correctly.

var shipMeth = this.getField("ShipMeth").value;

if (shipMeth == "UPS Ship")

    event.value = this.getField("UPSTax").value;

else if (shipMeth == "PickUp")

     event.value = this.getField("LocTax").value;

else

    event.value = 0;

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Engaged ,
Sep 18, 2018 Sep 18, 2018

Copy link to clipboard

Copied

I also noted the poster refered to a radio value of "PickUp" first and than "Pickup" with a lowercase "U".  Just make sure you use the right one.

Votes

Translate

Translate

Report

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 ,
Sep 18, 2018 Sep 18, 2018

Copy link to clipboard

Copied

LATEST

Yes, names are very important. All text between codes and field properties must match exactly.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

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
Engaged ,
Sep 18, 2018 Sep 18, 2018

Copy link to clipboard

Copied

Assuming your radios are named "ShipMeth" and their values are "UPS" and "PICKUP"

Inside TaxTot calculation script:

var UPSTax = this.getField("TUPSTaxt").value

var LocTax = this.getField("LocTax").value

var shipMeth = this.getField("ShipMeth").value

if (shipMeth == "UPS") this.getField("TaxTot").value = UPSTax

else if (shipMeth == "PICKUP") this.getField("TaxTot").value = LocTax

else this.getField("TaxTot").value = 0

Votes

Translate

Translate

Report

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