2 Replies Latest reply on Jan 29, 2015 7:33 AM by abt-jenks

    How to create a simple if than else statement

    abt-jenks

      I've been trying for hours to learn how to do a simple calculation to display text in one field based on what is selected in another dropdown box.  My first time doing this so I'm not sure what I'm doing wrong.  Here is what I have so far:

       

      // get the value of the Physician field

      var Physician = this.getField("Physician").value;

       

      // Display Number depending on Physician selected

      if(Physician=1) event.value = 100;

      else if (Physician = '2') event.value = 200;

      else if (Physician = '3') event.value = 300;

      else event.value = 0;

        • 1. Re: How to create a simple if than else statement
          try67 MVP & Adobe Community Professional

          You've made the classic mistake of using the wrong operator in the if-statements. The if-operator in JS is "==" (or "==="). "=" is the assignment-operator.

          Also, in the first statement you're comparing the values to a number and later on to a string. You need to be more consistent.

          So use this code:

           

          // get the value of the Physician field
          var Physician = this.getField("Physician").valueAsString;
          
          // Display Number depending on Physician selected
          if (Physician=="1") event.value = 100;
          else if (Physician == "2") event.value = 200;
          else if (Physician == "3") event.value = 300;
          else event.value = 0;
          

           

          Seeing your code, though, I don't think you need an if-statement at all... This code should do the same thing:

           

          event.value = Number(this.getField("Physician").valueAsString) * 100;
          
          • 2. Re: How to create a simple if than else statement
            abt-jenks Level 1

            You're amazing Gilad.  Thanks so much!