Copy link to clipboard
Copied
I have a text field called Name. I have two other text fields called City1 and City2. If the word Chicago is entered into the Name text field, I want the City1 text field to be visible and the City2 text field to be hidden. If the word Detroit is entered into the Name text field, I want the City2 text field to be visible and the City1 text field to be hidden. Any help is greatly appreciated.
Copy link to clipboard
Copied
What if neither Detroit or Chicago is entered into the Name field? If you want the fields hidden in this case, and you want to ignore case sensitivity in Detroit and Chicago, enter the follow custom validation script in the Name field:
if(/chicago/i.test(event.value))
{
this.getField("City1").display = display.visible;
this.getField("City2").display = display.hidden;
}
else if(/detroit/i.test(event.value))
{
this.getField("City1").display = display.hidden;
this.getField("City2").display = display.visible;
}
else
{
this.getField("City1").display = display.hidden;
this.getField("City2").display = display.hidden;
}
Copy link to clipboard
Copied
What happens when something else is entered into "Name"?
But here is some code to add to the "Name" Validation Script. It hides both fields on non-matching text entry.
// Validation Script for Name field
if(event.value == "Chicago"){
this.getField("City1").display = display.visible;
this.getField("City2").display = display.hidden;
}
if(event.value == "Detroit"){
this.getField("City1").display = display.hidden;
this.getField("City2").display = display.visible;
}
else {
this.getField("City1").display = display.hidden;
this.getField("City2").display = display.hidden;
}
Copy link to clipboard
Copied
When I type Chicago in the Name field, both boxes are hidden. But when I type Detroit in the Name field, it works correctly (City 1 is hidden and City2 is visible.
Copy link to clipboard
Copied
Add the word else and a space in front of @Thom Parker 's 2nd "if".
Copy link to clipboard
Copied
Now it works. Thank you!
Copy link to clipboard
Copied
What if neither Detroit or Chicago is entered into the Name field? If you want the fields hidden in this case, and you want to ignore case sensitivity in Detroit and Chicago, enter the follow custom validation script in the Name field:
if(/chicago/i.test(event.value))
{
this.getField("City1").display = display.visible;
this.getField("City2").display = display.hidden;
}
else if(/detroit/i.test(event.value))
{
this.getField("City1").display = display.hidden;
this.getField("City2").display = display.visible;
}
else
{
this.getField("City1").display = display.hidden;
this.getField("City2").display = display.hidden;
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now