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

Javascript calculation won't update when dropdown value changes

New Here ,
Jun 20, 2024 Jun 20, 2024

I've spent 2 hours on this and getting nowhere -- this seems pretty simple and I'd appreciate any help!

 

I have a dropdown "Retired?" with Yes/No options. The properties are set to "Commit selected value immediately."

I have a field called "Liquidity" that should do a calculation if the dropdown is Yes, and do nothing if No. 

 

Here's the code in the field:

var a = Number(this.getField("AP1").valueAsString);
var b = Number(this.getField("AP2").valueAsString);
var c = Number(this.getField("AP3").valueAsString);
var d = Number(this.getField("AP4").valueAsString);
var e = Number(this.getField("AP9").valueAsString);
var x = this.getField("Retired?").value;

if (x = "Yes") {
event.value=(a+b+c+d+e)*.04;
} else {
event.value = "";
}

MY PROBLEM: no matter the dropdown selection, the calculation (a+b+c+d+e)*.04 always appears.

 

To check the value of the dropdown, I created a test field to display it with this code:

     var x = this.getField("Retired?").value;
     event.value = x

When I change the dropdown, the field updates with the correct value.

What am I missing to get the dropdown value to be recognized in the calculation?

TOPICS
JavaScript , PDF forms
748
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Jun 20, 2024 Jun 20, 2024

Use this:

if (x == "Yes") {

View solution in original post

Translate
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 ,
Jun 20, 2024 Jun 20, 2024

Use this:

if (x == "Yes") {

Translate
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 ,
Jun 20, 2024 Jun 20, 2024
LATEST

Thank you SO MUCH!  It worked!

I knew it would be something simple but being new to javascript, I had no idea what keywords I would use in a Google search. 

Translate
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