Skip to main content
Known Participant
December 29, 2017
Answered

Performing a function dependent on drop down menu selection.

  • December 29, 2017
  • 1 reply
  • 745 views

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.

This topic has been closed for replies.
Correct answer try67

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;

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
December 29, 2017

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;

Known Participant
December 29, 2017

-_-

you have no idea how many time I messed with this one stupid line of code... lol. Thank you so much!