Hi,
I have an if statement based on the result of a calculation. The if statement works if you enter a number manually but it won’t work as the result of a calculation. Can anyone let me know why?
I have copied the if statement below. Text 2 is the calculation field.
if (this.getField("Text2").value=="18") {
event.value = "Category 1"
} else if (this.getField("Text2").value=="12") {
event.value = "Category 1"
} else if (this.getField("Text2").value=="11") {
event.value = "Category 1"
} else if (this.getField("Text2").value=="16") {
event.value = "Category 3"
} else if (this.getField("Text2").value=="10") {
event.value = "Category 3"
} else if (this.getField("Text2").value=="17") {
event.value = "Category 2"
} else { event.value = 0}
Cheers
Try using this.getField("Text2").valueAsString instead of .value and see if that works properly
Also, I would suggest using a 'Switch' command instead of the multiple if/else if commands.
switch(this.getField("Text2").valueAsString) {
case '18':
case '12':
case '11':
event.value = "Category 1"
break;
case '16':
case '10':
event.value = "Category 3"
break;
case '17':
event.value = "Category 2"
break;
default:
event.value = 0
}
Thanks for the reply.
The switch statement is working the same as the if else statement in that when you enter the number manually, the correct response displays but the result won't display based on the calculation?
The calculation is simply the sum of 3 radio button values.
Again I appreciate the help.
I'm not understanding exactly what you are saying. What is the calculation you are using? How is the calculated field (I am assuming 'Text2' is your calculated field) formatted?
Are you sure that the calculated values are EXACTLY 18, 12, etc.? If they are 18.01 and you are have the format set to 0 decimal places, then it won't work because you are comparing the actual value, not the formated value. Other than that, I'm not sure exactly what the issue you are having is.
I have 3 radio buttons that are yes no's, the response to these 3 criteria questions will determin the result (category 1, 2, or 3).
Giving each of the possible responses a different value was the easiest way to identify the different result categories.
Text2 is used to calculate the total from the criteria questions.
e.g Y + N + N = 18; 18 equals category 1.
the if else statement above will give the correct result if the number is entered manually but not as a result of the calculation.
E.g if 18 is entered into the box Category 1 appears in Text3
if the yes no's are selected and totalled in Text2 the result won't display.
North America
Europe, Middle East and Africa
Asia Pacific