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

Calculated field dependent on radio button selection w/ diff rates

New Here ,
Nov 02, 2018 Nov 02, 2018

Copy link to clipboard

Copied

Hi - I'm new here. I usually just google when I can't figure something out but I can't find a close enough scenario for me to figure this out. I'm not a pro at java or scripting - I'm self-taught; this is how I learn - so bear with me.

i have a form that calculates mileage reimbursement amount (miles multiplied by reimbursement rate) but I want the user to select a radio button for either "regular" or "relocation" because the reimbursement rates are different for each. How can I get the subtotal field to use the reimbursement rate related to the corresponding mileage type?

I'd appreciate any ideas.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

644

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

correct answers 1 Correct answer

Engaged , Nov 06, 2018 Nov 06, 2018

Hello! Here is something you can try. This is going to depend on some setup from you. If you have a document you can share I would be happy to help... otherwise see what you can do with this.... it should get you close. I tried to put in comments to help you with what the setup should be as well as what the script was doing. Place this script on a Submit button for the user to click when they have completed the form.

// Name your radio button for regular  regularRate

var regularSelected = this.get

...

Votes

Translate

Translate
Engaged ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

Hello! Here is something you can try. This is going to depend on some setup from you. If you have a document you can share I would be happy to help... otherwise see what you can do with this.... it should get you close. I tried to put in comments to help you with what the setup should be as well as what the script was doing. Place this script on a Submit button for the user to click when they have completed the form.

// Name your radio button for regular  regularRate

var regularSelected = this.getField("regularRate").value; 

// Name your radio button for relocation   relocationRate

var relocationSelected = this.getField("relocationRate").value;

// Name the field the user puts the miles traveled   milesTraveled

var milesTraveled = this.getField("milesTraveled").value;

// The dollar amount of reimbursment for regular...

var regularReimbursement = 1.25;

// The dollar amount of reimbursment for relocation...

var relocationReimbursement = 2.50;

// If the regular radio is selected... 

if (regularSelected == "regularRate"){

    payoutTotal = milesTraveled * regularReimbursement;

    // Name a text box  payoutTotal  the math equation will populate in that field

    this.getField("payoutTotal").value = payoutTotal;

}

// If the relocation radio is selected...

if (relocationSelected == "relocationRate"){ 

    payoutTotal = milesTraveled * relocationReimbursement;

    // Name a text box  payoutTotal  the math equation will populate in that field

    this.getField("payoutTotal").value = payoutTotal;

}

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 ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

Actually I will do you one better....

Here is a very basic form I created for you:

https://drive.google.com/open?id=1JGEzZ0x7Jaznu5Jwl-vwty8MVIw5XbyO

To see the script and edit the dollar amount for the mileage reimbursement right click on the submit button, go to properties...then go to the actions tab. Click on the Run a JavaScript and then select edit. Change the numbers as you see fit.

Hope this helps you!

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 ,
Nov 06, 2018 Nov 06, 2018

Copy link to clipboard

Copied

Thanks SO much for your expertise! Unfortunately, adding a "submit" button doesn't work for me because I'm updating an existing form for a State agency so I cannot add a button. Is a button the only way this is possible?

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 ,
Nov 07, 2018 Nov 07, 2018

Copy link to clipboard

Copied

LATEST

You can actually take the script that I wrote and put it in the Document JavaScripts.

However the problem I believe you are going to run into is that if the fields aren't populated it is going to cause errors.

Also you will have to run the Document JavaScript every time a new calculation is needed.

Any chance you could email me the form? I may be able to help that way? I understand you might not be able to share documents but if you can feel free to email it to...

corey.wolfe@gmail.com

Try to include some details of how the document is used as well.

Oh wait!... I have an idea that MAY work...

Might be able to make this a tool that runs from a menu?

What version of Acrobat are you using?

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