Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Trying to write a switch case, Help please!

Community Beginner ,
May 26, 2021 May 26, 2021

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
2.1K
Translate
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 Expert ,
May 26, 2021 May 26, 2021

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;

}

 
Translate
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

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.

Translate
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 Expert ,
May 26, 2021 May 26, 2021

Where does you use the script?

Translate
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

In the Account Type Field where Joint may be selected.

Translate
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

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.

Translate
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

I am using the script in the custom validation section

Translate
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 Expert ,
May 26, 2021 May 26, 2021
LATEST

Change the selection and it will fires the script.

Translate
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