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

SOLVED

Switch - using another fields rawValue

Avatar

Level 4

Hi,

Ive got the below code on a fields (not the worktype dropdown list's field) and want to use a switch statement to combine a variable and this fields rawValue with the variable being combined depending on the rawValue of the dropdown list - (the code below is commented to clarify what im trying to do)

anyone know why this isn't working.....

// this code is attached to the exit event a field called employname (the next field the user completes after the worktype list selection)  

switch (worktype.rawValue)

case "1": {

//where the "1" is the rawValue of the worktype dropdown list following selection by user

page3.para5.rawValue = f1.value + this.rawValue +".";

}

         break;

case "2": {

page3.para5.rawValue = f1.value + this.rawValue +"222222.";

}

        break;

case "3": {

page3.para5.rawValue = f1.value + this.rawValue +"3333";

}}
thanks folks

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Greg,

There are a couple of things going on here. First because the script is in  the exit event - if a user goes back to the worktype and changes the value, it won't trigger the calc in the exit event. It might be better to put the script in the calculate event of "page3.para5.rawValue" and have it look back at worktype and employeename.

Also the curly brackets are only required to enclose the switch statement; not each individual case.

switch (worktype.rawValue)

{ // curley bracket here to start the switch cases

     case "1":     

     page3.para5.rawValue = f1.value + this.rawValue +".";

     break;

     case "2":

     ...

     break;

} // curley bracket to close the switch statement

Hope that helps,

Niall

View solution in original post

5 Replies

Avatar

Correct answer by
Level 10

Hi Greg,

There are a couple of things going on here. First because the script is in  the exit event - if a user goes back to the worktype and changes the value, it won't trigger the calc in the exit event. It might be better to put the script in the calculate event of "page3.para5.rawValue" and have it look back at worktype and employeename.

Also the curly brackets are only required to enclose the switch statement; not each individual case.

switch (worktype.rawValue)

{ // curley bracket here to start the switch cases

     case "1":     

     page3.para5.rawValue = f1.value + this.rawValue +".";

     break;

     case "2":

     ...

     break;

} // curley bracket to close the switch statement

Hope that helps,

Niall

Avatar

Level 10

What is not working? The assignment to "page3.para5.rawValue"? Do you want to concatenate strings together or do addition?

The code below was attached to the exit event on drop-down "dropDown1". It concatenates the value of "dropDown1" with the value of "textField1" and populates "textField2".

// form1.page1.dropDown1::exit - (JavaScript, client)

switch (this.rawValue) {

     case "1":

          form1.page1.textField2.rawValue = this.rawValue + form1.page1.textField1.rawValue;

          break;

     case "2":

         form1.page1.textField2.rawValue = this.rawValue + form1.page1.textField1.rawValue;

         break;

     case "3":

         form1.page1.textField2.rawValue = this.rawValue + form1.page1.textField1.rawValue;

         break;

     default:

         break;

}

Avatar

Level 4

Thanks NIall, that got the switch statement aspect working

Excuse the ignorance (I have an abundance) but if I attach it to the calculate event (which seems a good idea) what triggers that event/calculate to run the code... I suppose Im asking when and why that event type fires/is best used ?

thanks

Greg

Avatar

Level 4

Ignore me; raided the scripting reference (and understood it for once.)

thanks

Avatar

Level 10

Hi Greg,

There is a sample here that tries to show how and when events fire.

Niall