Skip navigation
yep80
Currently Being Moderated

if statement

Aug 8, 2012 7:46 PM

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

 
Replies
  • Currently Being Moderated
    Aug 9, 2012 5:55 AM   in reply to yep80

    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

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 9, 2012 4:02 PM   in reply to yep80

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points