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

Need help incorporating a checkbox to a calculation

New Here ,
May 02, 2022 May 02, 2022

Copy link to clipboard

Copied

Hi,

I am developing a PDF fillable form for travel requests. I want to be able to calculate additional mileage with a checkbox. If a person inputs the mileage into the mileage box, and the current govt. rate, then it will calculate in a different field. I can do that calculation as "product". However, I would like to add that if the person selects the checkbox marked "RT-round trip" it will double the mileage and times by the govt. rate. I am assuming I can only do this using javascript and am a "noobie" to writing javascript. I have looked at several discussions and websites for help but can't quite seem to grasp what is needed. The fields are identified as such: "Estim.Miles1", "Check Box 1", "Rate/Mile", "Mileage.TOTAL" Any help on this would be appreciated.

Thank you

TOPICS
Acrobat SDK and JavaScript

Views

290

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 ,
May 10, 2022 May 10, 2022

Copy link to clipboard

Copied

Hi,

 

This is possible, using code like the following in the Actions -> Add -> Run JavaScript of the checkbox.

 

// change the value inbetween the "", to your field name
var mileageField = this.getField("mileageField");
// Assuming the checkbox exports a value of "Yes" when clicked
// if you change that value, you need to change it here
if ( event.target.value == "Yes"){
    // double the value in the field
    // I have not covered the value not being a number.
    mileageField.value = mileageField.value * 2;
} else {
    // assumtion if it is unchecked, we should halve the value.
    mileageField.value = mileageField.value / 2;
}

 

edit : corrected typo.

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 ,
May 10, 2022 May 10, 2022

Copy link to clipboard

Copied

There is 'dot'  in front of mileageField  that needs to be removed  =.mileageField.value / 2;

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 ,
May 16, 2022 May 16, 2022

Copy link to clipboard

Copied

LATEST

Thank you both very much!

I have been out on PTO and will get to this later in the week.

 

Thanks again

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