Welcome Dialog

Welcome to the Community!

We have a brand new look! Take a tour with us and explore the latest updates on Adobe Support Community.


Trying to write a switch case, Help please!

Community Beginner ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

Hello Everyone,

 

I am trying to write a switch case that uses an if/then statement inside it but I keep getting a Syntax error. I would like certain fields to be outlined green if Joint is selected and they aren't blank, and red if Joint is selected but they are blank. Please let me know what I am doing wrong...

 

switch(event.value) {case "Joint":
{
if((this.getField("LNS").value !== "") && (this.getField("FNS").value !== ""))
this.getField("LNS").strokeColor=color.green;
this.getField("FNS").strokeColor=color.green;
else if((this.getField("LNS").value == "") && (this.getField("FNS").value == ""))
this.getField("LNS").strokeColor=color.red;
this.getField("FNS").strokeColor=color.red;
};
break;

case "Individual"||"IRA"||"Entity"||"Trust"||"Individual 401K"||"Direct Business 529":

this.getField("LNS").strokeColor=color.black;
this.getField("FNS").strokeColor=color.black;
break;


default:

this.getField("LNS").strokeColor=color.black;
this.getField("FNS").strokeColor=color.black;

break;

}

 

 

Thank You Kindly!

TOPICS
How to, JavaScript, PDF forms

Views

500

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

Try this:

switch(event.value) {
case "Joint":
{
if((this.getField("LNS").value !== "") && (this.getField("FNS").value !== ""))
{
this.getField("LNS").strokeColor=color.green;
this.getField("FNS").strokeColor=color.green;
}
else if((this.getField("LNS").value == "") && (this.getField("FNS").value == ""))
{
this.getField("LNS").strokeColor=color.red;
this.getField("FNS").strokeColor=color.red;
}
};
break;

case "Individual":
case "IRA":
case "Entity":
case "Trust":
case "Individual 401K":
case"Direct Business 529":
this.getField("LNS").strokeColor=color.black;
this.getField("FNS").strokeColor=color.black;
break;

default:

this.getField("LNS").strokeColor=color.black;
this.getField("FNS").strokeColor=color.black;

break;

}

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

Thank you for your reply! Your changes eliminated the syntax error, but when I type something into the fields to test for not blank, the outline remains red, instead of changing to green.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

Where does you use the script?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

In the Account Type Field where Joint may be selected.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

Yes, but each field has multiple actions. It's very important to say which action you choose, for example "mouse down" or "validate". Only one will work for any given script.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

I am using the script in the custom validation section

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
May 26, 2021 May 26, 2021

Copy link to clipboard

Copied

LATEST

Change the selection and it will fires the script.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines