Skip to main content
Participant
May 2, 2022 4:55 PM UTC
Question

Need help incorporating a checkbox to a calculation

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

This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Participant
May 16, 2022 8:44 PM UTC

Thank you both very much!

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

 

Thanks again

Translate
BarlaeDC
Community Expert
Community Expert
May 10, 2022 10:55 AM UTC

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.

Translate
Nesa Nurani
Community Expert
Community Expert
May 10, 2022 3:57 PM UTC

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

Translate