1 Reply Latest reply on Jun 4, 2010 12:14 AM by try67

    If Statement, help.

    Pixielix_UK

      I have the following calculation:

       

      if (this.getField("CB-Acrobatic").value=="3" &&

      this.getField("Acrobatics-Ranks").value>9) {

      event.value = 4;

      } or

      else event.value = "0";

       

      But I also want it to check the following:

       

      if (this.getField("CB-Acrobatic").value=="3" &&

      this.getField("Acrobatics-Ranks").value<9) {

      event.value = 2;

      } or

      else event.value = "0";

       

      How would I go about combining these two calculations into one tidy script?

        • 1. Re: If Statement, help.
          try67 MVP & Adobe Community Professional

          First of all, there's no such thing as "or else" in JavaScript. Use just "else", or "else if" (see below).
          To achieve what you describe the best way is to split the if statments, like so:

          if (this.getField("CB-Acrobatic").value==3) {
                if (this.getField("Acrobatics-Ranks").value>9) {
                     event.value = 4;
                } else if (this.getField("Acrobatics-Ranks").value<9) {
                     event.value = 2;
                } else event.value = 0;
          }

           

          Also, it's not a good idea to mix the type of values. Use either strings, or numbers.