Skip to main content
BradSmithSC
Participating Frequently
June 10, 2016
Answered

Show/hide multiple fields on drop-down choice using if else

  • June 10, 2016
  • 1 reply
  • 2830 views

Goal is to show or hide three fields depending on a drop-down choice. Show if X, hide if Y.

Getting a syntax error on line 6 when adding to the mouse-up trigger of the dropdown field.

Are multiple actions allowed for each if condition?

if(event.target.value = "Yes")

  getField("Top_inches").display = display.visible;

  getField("Top_numerator").display = display.visible;

  getField("Top_denominator").display = display.visible;

else

  getField("Top_inches").display = display.hidden;

  getField("Top_numerator").display = display.hidden;

  getField("Top_denominator").display = display.hidden;

This topic has been closed for replies.
Correct answer try67

You have at least two syntax errors. The first is that you used the wrong operator for the comparison. It's "==", not "=" (that is the value assignment operator).

The second is that you didn't put the code blocks inside curly brackets.

So your code should be:

if (event.target.value == "Yes") {

    this.getField("Top_inches").display = display.visible;

    this.getField("Top_numerator").display = display.visible;

    this.getField("Top_denominator").display = display.visible;

} else {

    this.getField("Top_inches").display = display.hidden;

    this.getField("Top_numerator").display = display.hidden;

    this.getField("Top_denominator").display = display.hidden;

}

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 10, 2016

You have at least two syntax errors. The first is that you used the wrong operator for the comparison. It's "==", not "=" (that is the value assignment operator).

The second is that you didn't put the code blocks inside curly brackets.

So your code should be:

if (event.target.value == "Yes") {

    this.getField("Top_inches").display = display.visible;

    this.getField("Top_numerator").display = display.visible;

    this.getField("Top_denominator").display = display.visible;

} else {

    this.getField("Top_inches").display = display.hidden;

    this.getField("Top_numerator").display = display.hidden;

    this.getField("Top_denominator").display = display.hidden;

}

try67
Community Expert
Community Expert
June 10, 2016

PS. If you're getting an error message please post it in full. It is very helpful in finding and fixing problems with the code.