Skip to main content
Inspiring
April 15, 2020
Answered

Conditional read-only field based on another dropdown field

  • April 15, 2020
  • 1 reply
  • 1075 views

I'd like a dropdown field's selection to trigger a read-only text field to appear below it. That text field may need to be multi-line content. Can anyone share how do I do this with JavaScript applied to that dropdown field? 

This topic has been closed for replies.
Correct answer try67

Yes, but then you would need to either use a different field or to set the field's value, instead of its display.

For example:

if (this.getField("Dropdown1").valueAsString=="Option1") event.value = "text in English";

else if (this.getField("Dropdown1").valueAsString=="Option2") event.value = "texto en Español";

1 reply

try67
Community Expert
Community Expert
April 15, 2020

Let's say that fielda are called "Text1" and "Dropdown1" and you want to show the former if "Option1" is selected in the latter. Use this code as the custom calculation script of the text field:

 

event.target.display = (this.getField("Dropdown1").valueAsString=="Option1") ? display.visible : display.hidden;

 

Then just set the text field's default value to the desired text, and set the drop-down to commit the selected value immediately, and you're done!

Inspiring
April 15, 2020

Super, thank you. What if I wanted to have alternative language there if they chose Option2?

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
April 15, 2020

Yes, but then you would need to either use a different field or to set the field's value, instead of its display.

For example:

if (this.getField("Dropdown1").valueAsString=="Option1") event.value = "text in English";

else if (this.getField("Dropdown1").valueAsString=="Option2") event.value = "texto en Español";