Skip to main content
Known Participant
June 23, 2025
Answered

How to write validation script for one dropdown that is conditional based on another dd's selection

  • June 23, 2025
  • 2 replies
  • 369 views

There are two different dropdowns (named "dd1" and "dd2") with the same 13 selections ("a" through "m")

When "a" or "b" is selected, a hide field should to appear.

Example script for both dd1 and dd2:

if((event.value =="a") || (event.value =="b")) {
this.getField("Hide").display = display.visible;
} else {
this.getField("Hide").display = display.hidden;
}

 

This script works for both dropdown's, however, if the selection for "dd1" was NOT

 "a" or "b", the hide field needs to stay hidden even if  "a" or "b" is selected from "dd2".

 

Is there a way to add this condition to the validation script for "dd2" (i.e., reference "dd1" and it's selections)?

 

Any help would be appreciated!

Correct answer Nesa Nurani

Something like this:

var dd1Value = this.getField("dd1").value;
var dd2Value = event.value;

if ((dd1Value == "a" || dd1Value == "b") && (dd2Value == "a" || dd2Value == "b")) {
 this.getField("Hide").display = display.visible;} 
else {
 this.getField("Hide").display = display.hidden;}

2 replies

Nesa Nurani
Community Expert
Community Expert
June 24, 2025

If implemented this way, the second script becomes redundant. It cannot influence the visibility of the "Hide" field unless dd1 is set to "a" or "b"—but in that case, the field is already made visible by the primary script tied to dd1. Therefore, the second script serves no functional purpose in this setup.

slaronAuthor
Known Participant
June 24, 2025

The example script shown above is to have the text field "Hide" visible when the either "a" or "b" is selected from the dropdown and hidden when any of the other options (e.g., "c") is selected. This portion works as is should. The problem I have is that if "a" or "b" is NOT selected in both dd1 and dd2, the "Hide" field needs to be hidden, even if "a" or "b" is selected from dd2. Is there a way to write in the validation code for dd2, that if "dd1" event.value does not equal "a" or "b" then the text field "Hide" should be hidden? I am not sure how to refer to a separate dropdown field (i.e., refer to "dd1" in the validation script for "dd2". I hope this explains what I am trying to do more clearly.

Nesa Nurani
Community Expert
Nesa NuraniCommunity ExpertCorrect answer
Community Expert
June 24, 2025

Something like this:

var dd1Value = this.getField("dd1").value;
var dd2Value = event.value;

if ((dd1Value == "a" || dd1Value == "b") && (dd2Value == "a" || dd2Value == "b")) {
 this.getField("Hide").display = display.visible;} 
else {
 this.getField("Hide").display = display.hidden;}
Bernd Alheit
Community Expert
Community Expert
June 24, 2025

Check also the value of the other dropdown.