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
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.
Copy link to clipboard
Copied
There is 'dot' in front of mileageField that needs to be removed =.mileageField.value / 2;
Copy link to clipboard
Copied
Thank you both very much!
I have been out on PTO and will get to this later in the week.
Thanks again