Skip to main content
Participant
June 20, 2024
Answered

Javascript calculation won't update when dropdown value changes

  • June 20, 2024
  • 1 reply
  • 682 views

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?

This topic has been closed for replies.
Correct answer Bernd Alheit

Use this:

if (x == "Yes") {

1 reply

Bernd Alheit
Community Expert
Bernd AlheitCommunity ExpertCorrect answer
Community Expert
June 20, 2024

Use this:

if (x == "Yes") {

Participant
June 20, 2024

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.