Skip to main content
Participant
June 19, 2019
Answered

Show/Hide field based on a choice from a dropdown field which contains a specific word

  • June 19, 2019
  • 1 reply
  • 1602 views

I have a dropdown field (Type_Study) with 10 options, 4 of which begin with the word "Sensitization."

I have 2 fields which only need to be visible if:

a) the choice from the dropdown includes "Sensitization" or "all", and

b) if a different dropdown (Storage1) is not equal to "Select Option"

I believe I would need to add a custom calculation script to the fields to be visible or hidden and I have the script to make the field visible based on b) but I do not know how to script a) and combine it with b).

So far, I have:

if (this.getField("Storage1").value != "Select Option") {    

event.target.display = display.visible;

} else {

event.target.display = display.hidden;

}

Any help would be appreciated.

Thanks,

Jane

This topic has been closed for replies.
Correct answer try67

OK, thanks.

I was hoping not to have to spell out the full value... hence my use of contains but if equals is simpler, I can write the full text of the field. Let's do that and I will replace my text in " " with full text.

Many thanks.

Jane


No need, it's possible to check if one value contains another, it's just a bit trickier.

Try this code:

var v1 = this.getField("Type_Study").valueAsString;

var v2 = this.getField("Storage1").valueAsString;

if ((/All 3 Assays/.test(v1) || /DPRA/.test(v1) || /KeratinoSens/.test(v1)) && v2!="Select Option") {

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

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

} else {

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

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

}

(I'm still not sure what are the names of the fields you want to show/hide...)

1 reply

try67
Community Expert
Community Expert
June 20, 2019

Because you want to do it based on the value of multiple fields, it's a bit more complicated.

You can use this code as the custom calculation script of a (hidden) text field to achieve it:

var v1 = this.getField("Sensitization").valueAsString;

var v2 = this.getField("Storage1").valueAsString;

if ((/Sensitization/.test(v1) || /all/.test(v1)) && v2!="Select Option") {

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

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

} else {

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

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

}

You'll need to enter the actual field names in lines 4, 5, 7 and 8, of course.

Edit: code fixed

try67
Community Expert
Community Expert
June 20, 2019

There was a mistake in the code above. I fixed it now.