Skip to main content
Participating Frequently
June 7, 2020
Question

Unable to hide/reveal images like text

  • June 7, 2020
  • 2 replies
  • 1053 views

Hey all,

 

I'm working on a project where I need the choice on a dropdown menu to reveal and hide certain fields. I wrote a code that works just fine for text fields but will not work with an image field. Code below:

 

switch(event.value) {

 

case "Option A":

this.getField("Text 1").display=display.visible;
this.getField("Text 2").display=display.hidden;
this.getField("Image 1").display=display.visible;
this.getField("Image 2").display=display.hidden;
break;

 

case "Option B":

this.getField("Text 1").display=display.hidden;
this.getField("Text 2").display=display.visible;
this.getField("Image 1").display=display.hidden;
this.getField("Image 2").display=display.visible;
break;

 

}

 

With this code applied to my Dropdown field my Text fields swap just fine, but the Images remain visible no matter the dropdown option chosen. Another thing I noticed is that whenever I rename an Image field it becomes a Button automatically. I thought that might be the issue, but I adjusted the code for the auto-populated Image field name and still had the same issue. Are Images and/or Buttons unable to be hidden/revealed, or is there a setting I am missing somewhere?

 

Cheers!

This topic has been closed for replies.

2 replies

Inspiring
April 25, 2021

I am suffering from exactly the same symptoms.
Only the image field is not hidden.

 

var PAPA1 = this.getField ("PAPA_1");            //Text Field
var MAMA1 = this.getField ("MAMA_1");         //Image Field

 

PAPA1.display = display.hidden;                    //It disappears from the screen.
MAMA1.display = display.hidden;                  //It doesn't disappear from the screen.

 

No error appears here.

It just doesn't disappear.

 

 

try67
Community Expert
Community Expert
April 25, 2021

Can you share the file with us?

Bernd Alheit
Community Expert
Community Expert
June 7, 2020

Check the Javascript console for errors.

Participating Frequently
June 7, 2020

Hi Bernd,

 

I am getting this from the Debugger:

SyntaxError: syntax error
1:Console:Exec
undefined

 

However, when I remove the image code and just include the text field codes in the debugger I get the same error message. But if I utilize the text-field-only code in my Custom Calculation Script, the text fields behave exactly as intended when the different dropdown options are selected.

try67
Community Expert
Community Expert
June 7, 2020

Add the code again, change the value of the field and then check the JS Console once more.

That error is from something you executed from the Console. It has nothing to do with it.