Expand my Community achievements bar.

Multiple rawValues and switch statements - can you do this?

Avatar

Former Community Member

Hi, a simple question (i hope)

first i have to use javascript for his one....

Im just starting a form and it will have about a dozen dropdown lists (over about 15 pages), each with quite a few variables (i feel a headache coming on already...)

and what i would like to be able to do is have text fields at the end of the form (hidden) and insert data into them depending on what combination of choices the user has made in some or all of the dropdown lists.

I know how to get a standard switch statement to work fine but can you (and if so what is the syntax like) do this with multiple lists - and what event would be best to link it to - calculate perhaps?

the switch would be using stored variables and user entered data to produce composite output to the text field (so case: listA.rawvalue = 1 and listB.rawvalue = nine, and listC.rawvalue = cat etc etc [then] this.rawvalue = v1.value + listB.rawvalue etc.....

I'm sure you get the issue im struggling with  - I've tried it a few ways but my syntax must be off somewhere

can anyone assist with the syntax for this kind of thing --or a sample would be fantastic.

cheers

5 Replies

Avatar

Former Community Member

Hey Legallogic!

I'm not 100% certain I understand what you are struggling with but I'd be happy to help.  If you could provide an alternate explanation of your issue I'll take a look and help you solve it.  What I *think* you're asking about is in reference to the test case of a switch statement.  Typically a switch would be used to test the value of one particular variable, so:

switch (varTest)

{

     case "A":

          //Do something here

          break;

     case "B":

          //Do something else here

          break;

     default:

          //Do something cool here instead

          break;

}

Are you asking how to use a single switch to test the value of multiple variables (or fields)?  If so, my recommendation would be to simply use and if/else if/else block as you can craft your test cases however you'd like for those.

Like I said, I may not have understood the issue here so feel free to shoot me an email and I'll take a peek!

Josh Boyle

Cardinal Solutions Group

jboyle@cardinalsolutions.com

Avatar

Former Community Member

HI,

yes it's a case of single switch to test the value of multiple variables

so imagine we have 5 dropdown lists - i just wanted some idea for the codeto make an  output field (called Output say) to = A (A will be a combination of stored variables, lists raw.values and other user fields (like name and address) if you chose options 1 1 1 1, to equal B (same story about content) if you chose 1,1,1,2 and so on through the various permutations.

someone (ages ago) said switch was simpler but i'm happy either way....

i do some (very) low level java, so should be o.k. once i clap eyes on a similar example (good old monkey see monkey do....)

thanks

Avatar

Former Community Member

Hey Legallogic!

What kind of values will the drop-downs have? As for the output field, what kind of values would it have? In other words, are you wanting to add all the values of drop-down lists to the output field as a comma-separated list (i.e. value1,value2,value3)?

Avatar

Former Community Member

EDIT:  I didn't realize replying to the email I receive as part of my subscription to this thread would enter my response for me.  Cool!

Avatar

Former Community Member

Hi Josh,

I think i might have (finally) got it working... finally

this type of thing seems to work attached to the calculate field of the text field

i have three dropdown lists (name  ..... age and.... type of car  -- and i have two stored variables - good car and bad car (v1 and v2).

not working with numeric data, but with text for our stuff - so this produces a paragraph of text which integrates the variables

if(page1.name.rawValue == "1" && page1.age.rawValue == "1" && page1.car.rawValue == "1") {

this.rawValue = "Hi there" + page1.name.rawValue + "you're " + page1.age.rawValue + "years old" + "and drive a " + page1.car.rawValue  + "which is a" + v1.value;

} else if(page1. name.rawValue == "1" && page1.age.rawValue == "1" && page1.car.rawValue == "2") {

this.rawValue = v1.value + v2.value + "Hi there" + page1.name.rawValue + "you're " + page1.age.rawValue + "years old" + "and drive a " + page1.car.rawValue  + "which is a" + v2.value;

}

//and so on through the options......

thanks for the help - this is a great forum