Copy link to clipboard
Copied
I am building a PDF form for the company I work for. One thing that is requested to happen in this form is to add numbers in two fields based on what is selected in a drop down menu. Below I am going to list out the fields, and my initial logic, I am hoping someone can point out what I am doing incorrectly and suggest the best way to code this.
The form fields are named as follows:
OwnerPolicyPurchase (this is a drop down selection menu with only two choices: Yes and No)
AppraiserFee
BasePremiumforTitlePolicy
TitleExamination
SubtotalExcludedAmounts (this is a display field that will output the value depending on the Yes/No selection)
The logic is to work like this:
IF Yes is selected in the OwnerPolicyPurchase drop down menu, THEN the two fields (AppraiserFee and Base PremiumforTitlePolicy) will be added together
IF No is selected in the OwnerPolicyPurchase drop down menu, THEN the two fields (AppraiserFee and Base TitleExamination) will be added together
The Sum based on the selection will then be displayed in the SubtotalExcludedAmounts field.
I setup the drop down menu export values to be Yes and No based on the corresponding selection, and I have selected the option to export the value immediately.
My initial code looked something like this (using the Custom calculation script for the SubtotalExcludedAmounts field):
var A=this.getField("OwnerPolicyPurchase").value;
var B=this.getField("AppraiserFee").value + this.getField("BasePremiumforTitlePolicy").value;
var C=this.getField("AppraiserFee").value + this.getField("TitleExamination").value;
if (A = "Yes") event.value=B;
else if(A="No") event.value=C;
Initially I thought this was working, I had data plugged into the form already and a number appeared based on the already selected drop down menu. Where it got weird was when I tried to select the other drop down menu option... nothing happened. The value in the form was the value previously in there. I tried switching around the variables (putting no first and then yes) and pre-populated the output field with only the formula corresponding to no. I tried doing this longhand without setting variables and had the same result.
After doing some research it looks like I need to use the function event.WillCommit in the Custom Keystroke Script option of the dropdown menu. I am just not sure how to set the functions up based on selection this area.
Any assistance will be greatly appreciated.
Copy link to clipboard
Copied
You've made a classic mistake of using the wrong operator... Change these lines:
if (A = "Yes") event.value=B;
else if(A="No") event.value=C;
To:
if (A == "Yes") event.value=B;
else if (A=="No") event.value=C;
Copy link to clipboard
Copied
You've made a classic mistake of using the wrong operator... Change these lines:
if (A = "Yes") event.value=B;
else if(A="No") event.value=C;
To:
if (A == "Yes") event.value=B;
else if (A=="No") event.value=C;
Copy link to clipboard
Copied
-_-
you have no idea how many time I messed with this one stupid line of code... lol. Thank you so much!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more