How to use a switch case function to reference options that is used numerous times in the previous drop-down?

Avatar

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Buckeye_Thomas
Level 1

24-02-2016

I am using JavaScript Coding in LiveCycle and developing dependent drop-down boxes but I am having difficulty writing the correct code. See example below. I am trying to use a multiple case function that references an option that is listed numerous times in the previous drop-down. The problem that I am running into is that when I reference Chevy or Nissan and any color, it is returning the results of the color under the "Ford" column only. I will still see the color options (Blue, Black, Green and Purple) in my second drop down and it looks fine, but then the third drop-down only references "Ford" colors and options. (I did not list the code for the third drop-down).

I want the customer to choose Chevy or Nissan and then have its dependent drop downs (based on the color they chose), but I cannot seem to make this work.

I hope this is clear enough (probably as mud…). I would greatly appreciate any help!!

form1.#subform[0].#subform[1].cboModels::exit - (JavaScript, client) 

cboColor.clearItems(); 

switch(this.rawValue){ 

case "Ford": 

  cboColor.addItem("Blue"); 

  cboColor.addItem("Black"); 

  cboColor.addItem("Green"); 

  cboColor.addItem("Purple"); 

  break; 

case "Chevy": 

  cboColor.addItem("Blue"); 

  cboColor.addItem("Black"); 

  cboColor.addItem("Green"); 

  cboColor.addItem("Purple"); 

  break; 

case "Nissan": 

  cboColor.addItem("Blue"); 

  cboColor.addItem("Black"); 

  cboColor.addItem("Green"); 

  cboColor.addItem("Purple"); 

  break; 

form1.#subform[0].#subform[1].cboColor::exit - (JavaScript, client)

cboPrice.clearItems(); 

switch(this.rawValue){ 

  case "Ford": 

  case "Green": 

  cboPrice.addItem("blah"); 

  cboPrice.addItem("blah"); 

  cboPrice.addItem("blah"); 

  cboPrice.addItem("blah"); 

  break; 

  case "Chevy": 

  case "Green": 

  cboPrice.addItem("blah"); 

  cboPrice.addItem("blah"); 

  cboPrice.addItem("blah"); 

  cboPrice.addItem("blah"); 

  break; 

  case "Nissan": 

  case "Green": 

  cboPrice.addItem("blah"); 

  cboPrice.addItem("blah"); 

  cboPrice.addItem("blah"); 

  cboPrice.addItem("blah"); 

  break; 

}

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_Bruce_Robertson
MVP

26-02-2016

You can use "\n" for a new line in a string, so

"Option 1,\nOption 2,\nOption 3";

Would put each one on its own line.

Bruce

Answers (7)

Answers (7)

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_Bruce_Robertson
MVP

02-03-2016

You should be able to add some code into the calculate event of a subform (so it doesn't actually return a value, but does get executed every time one of the referenced fields changes).  Choice any subform, but one that is a parent of all three fields is probably best.

So something like;

if (cboModel.rawValue == "Nissen" && cboColor.rawValue == "Green" && cboPartNumber.rawValue == "Option 3")

{

    xfa.host.messageBox("message ...")

}

Bruce

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_Bruce_Robertson
MVP

24-02-2016

Hi,

The switch case expression can't reference the two fields (cboModels and cboColor) like that and you probably don't want to populate the cboPrice in the exit event of cboColor in case they go back and change cboModel the cboColor exit event wont fire.

So try the following in the preOpen event of cboPrice.

switch(true){ 

  case cboColor.rawValue == "Green" && cboModels.rawValue == "Ford": 

    cboPrice.addItem("blah"); 

    cboPrice.addItem("blah"); 

    cboPrice.addItem("blah"); 

    cboPrice.addItem("blah"); 

    break

  case cboColor.rawValue == "Green" && cboModels.rawValue == "Chevy":  

    cboPrice.addItem("blah"); 

    cboPrice.addItem("blah"); 

    cboPrice.addItem("blah"); 

    cboPrice.addItem("blah"); 

    break

  case cboColor.rawValue == "Green" && cboModels.rawValue == "Nissan":  

    cboPrice.addItem("blah"); 

    cboPrice.addItem("blah"); 

    cboPrice.addItem("blah"); 

    cboPrice.addItem("blah"); 

  break

etc...

Bruce

Avatar

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Buckeye_Thomas
Level 1

02-03-2016

Bruce,

This worked great! Again, thank you. You've been a tremendous help!

Avatar

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Buckeye_Thomas
Level 1

01-03-2016

Bruce,

Thank you! So simple, should have known..

I want to thank you for all of your help thus far. I have one last question. I would like a message box to pop up if a certain option is selected in the drop down. Lets say they select "Option 3" under "Green and Nissan". Currently, I have a list box that automatically populates with the information I want after this selection is made, but I would also like a message box to popup on certain options. Is this possible?

Avatar

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Buckeye_Thomas
Level 1

26-02-2016

Bruce,

Good morning. Yes, the part numbers are unique. Is there any way to have them listed on top of each other? Such as:

Option 1

Option 2

Option 3

etc.

Avatar

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile

Avatar
Establish
MVP
_Bruce_Robertson
MVP

Likes

271 likes

Total Posts

1,782 posts

Correct reply

372 solutions
Top badges earned
Establish
Give Back 25
Give Back 10
Give Back 5
Give Back 3
View profile
_Bruce_Robertson
MVP

25-02-2016

Hi,

Maybe the simplest way would be the following JavaScript in the calculate event of the text field cboPartNumber;

switch(true){

  case cboColor.rawValue == "Green" && cboModels.rawValue == "Nissan":

    "Option 1, Option 2, Option 3";

  break;

...

}

There probably are better ways but would depend on the data, ... like are you part numbers always unique for a make/color combination?

Bruce

Avatar

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile

Avatar
Validate 1
Level 1
Buckeye_Thomas
Level 1

Like

1 like

Total Posts

6 posts

Correct reply

0 solutions
Top badges earned
Validate 1
Boost 1
View profile
Buckeye_Thomas
Level 1

25-02-2016

BR001_ACP,

This worked like a charm! Thank you for all of your help!

I do have one more question.

I would like for the final drop down selection to automatically populate a list or text field, but I am unsure how to write the code. I have this (see below), but it only shows the last option in the text field (Option 3). Is there anyway to have the field show all three?

Text Field is cboPartNumber

switch(this.rawValue){

  case cboModel.rawValue == "Nissan" && "Green":

   cboPartNumber.rawValue = ("Option 1");

   cboPartNumber.rawValue = ("Option 2");

   cboPartNumber.rawValue = ("Option 3");

   break;

}

Again, I appreciate all of your help!