Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Populating a numerical field by selecting from a dropdown

Avatar

Level 5

Good Morning All;

I have now gone through 38 pages on the form to try to figure this out myself. I must have missed something or this day is getting way to long.

I am trying to fill a numeric field based on what is selected from a dropdown box.

For testing, I am only using 2 fields

DropDownList1 and Numeric Field1

I if  (DropDownList1.rawValue == 1) {

     NumericField1.rawValue = 25;

    

}

Else;

(DropDownList1.rawValue == 2) {

     NumericField1.rawValue = 35;

    

}

Which did work. I am now getting the error " missing  ; before statement

6:XFA: form1 [0]: #subform [0]: DropDownList [0]: exit "

Specify items value is checked off on the bindings tab for DropDownList1.

I stated this with only one selection  which worked

if  (DropDownList1.rawValue == 1) {

     NumericField1.rawValue = 25;

}

Thanks All

Chomp

1 Accepted Solution

Avatar

Correct answer by
Level 10

If that's a copy/paste of your script you've got a semicolon after the "else" and "else" should be lower case.

And for nested ifs you need an "else if", so:

if (DropDownList1.rawValue == 1) {

     NumericField1.rawValue = 25;

}

else if (DropDownList1.rawValue == 2) {

     NumericField1.rawValue = 35;

}

//else if...

If you've got a lot of statements you might want to look at using a switch() statement which can be easier to read.

switch(DropDownList1.rawValue) {

     case "1":

          NumericField1.rawValue =  25;

          break;

     case "2":

          NumericField1.rawValue = 35;

          break;

//etc.

}

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

If that's a copy/paste of your script you've got a semicolon after the "else" and "else" should be lower case.

And for nested ifs you need an "else if", so:

if (DropDownList1.rawValue == 1) {

     NumericField1.rawValue = 25;

}

else if (DropDownList1.rawValue == 2) {

     NumericField1.rawValue = 35;

}

//else if...

If you've got a lot of statements you might want to look at using a switch() statement which can be easier to read.

switch(DropDownList1.rawValue) {

     case "1":

          NumericField1.rawValue =  25;

          break;

     case "2":

          NumericField1.rawValue = 35;

          break;

//etc.

}

Avatar

Level 5

Thank you Jono.

I had stated trying using the same "switch" statement but I used "if" instead.. Did not work that well.

Thanks Again

Chomp