Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Select items from 2 drop down lists based on a 3rd drop down list selection

Avatar

Level 1

This is probably easier than I am making it out to be. However, I am having a hard time figuring it out.

I have 3 drop down lists that are titled Branch, Division, and Office. Each Branch is associated with only 1 Division and 1 Office. Thus, if someone selects a branch, the correct division and office should automatically be filled in for the Division and Office drop down lists.

Any quick and easy ideas how to accomplish this?

This is what I have, which doesn't work.

form1.Page1SubformFlowed.ReviewInfoSubform.Branch::change - (JavaScript, client)

if ($.boundItem(xfa.event.newText) == "ASDB" || "JFDB1" || "JFDB2" || "RRDB" || "PSDB") {

  this.resolveNode("Division").rawValue = "DOD";

  this.resolveNode("Office").rawValue = "CDRH/ODE";

}

else if ($.boundItem(xfa.event.newText) == "CDDB" || "CEDB" || "CSDB" || "ICDB" || "IEDB" || "PIDB" || "SHDB" || "VSDB") {

this.resolveNode("Division").rawValue = "DCD";

this.resolveNode("Office").rawValue = "CDRH/ODE";

}

Thanks!

0 Replies

Avatar

Level 8

'$.boundItem(xfa.event.newText) ==' has to be placed after every conditional operator (||). So, if ($.boundItem(xfa.event.newText) == "ASDB" || $.boundItem(xfa.event.newText) =="JFDB1" || ....

Kyle

Avatar

Level 10

Probably easier to use a switch statement. Also, not sure if the $ will work with JavaScript there.

(I think this is the correct syntax for multiple case options.)

switch(this.boundItem(xfa.event.newText) {

     case "ASDB":

     case "JFDB1":

     case "JFDB2":

     case "RRDB":

     case "PSDB":

          this.resolveNode("Division").rawValue = "DOD";

          this.resolveNode("Office").rawValue = "CDRH/ODE";

          break;

     case "CDDB":

     case "CEDB":

          etc.

          break;

}

Avatar

Level 8

Apparently $ will work in JavaScript but I don't think it's officially supported. It's best not to use it in JavaScript if they do decide to completely deprecate it in later versions.

Here's another way using an object literal:

var myObj= {ASDB:{Division:"DOD",Office:"CDRH/ODE"},
    JFDB1:{Division:"DOD",Office:"CDRH/ODE"},
    JFDB2:{Division:"DOD",Office:"CDRH/ODE"},
    RRDB:{Division:"DOD",Office:"CDRH/ODE"},
    PSDB:{Division:"DOD",Office:"CDRH/ODE"},
    CDDB:{Division:"DCD",Office:"CDRH/ODE"},
    CEDB:{Division:"DCD",Office:"CDRH/ODE"},
    CSDB:{Division:"DCD",Office:"CDRH/ODE"}};

Division.rawValue=myObj[this.boundItem(xfa.event.newText)].Division;
Office.rawValue=myObj[this.boundItem(xfa.event.newText)].Office;

I always prefer working with arrays or objects when it comes to lists. That way if fields are changed/added/removed, the data (object literal in this case) remains the same and the only lines of code that need changing are the last two.

Kyle

Avatar

Level 10

Neat bit of code Kyle, I'll have to play around with it. I'm not that advanced in JavaScript.

Avatar

Level 8

And here you were teaching me JavaScript five years ago. Times have changed

Avatar

Level 10

I was teaching myself at the same time!

Unfortunately, it's not the only thing I do around my work...but the only coding I do is in Designer.