4 Replies Latest reply on Jun 19, 2014 7:02 AM by Damian__c

    Having trouble with if else when used with event.value... please help

    Damian__c

      Please can someone shed any light on where i'm going wrong.

      I have a pdf form that uses a drop down menu for the SubBrand and a series of checkboxes for the Location.

       

      the following code is placed as a custom calculation script in an address text field and what im after is dynamically setting the address based on the subbrand and location.

      However whats happening is the address only changes based on the location and not the subbrand.

      Does anyone please have any advice on this.

       

      Thanks

       

      if  ((this.getField("SubBrand").value == "Passion" || "Passion for Men") && (this.getField("Location").value == "WW")) {
          event.value = "Not Applicable";

      }

      else if ((this.getField("SubBrand").value == "Passion" || "Passion for Men") && (this.getField("Location").value == "US")) {

          event.value = "US02";

      }

      else if ((this.getField("SubBrand").value == "Passion" || "Passion for Men") && (this.getField("Location").value == "WH")) {

          event.value = "WH02";

      }

      else if ((this.getField("SubBrand").value == "Adventure" || "Liquid" || "Silver") && (this.getField("Location").value == "WW")) {

          event.value = "WW01";

      }

      else if ((this.getField("SubBrand").value == "Adventure" || "Liquid" || "Silver") && (this.getField("Location").value == "US")) {

          event.value = "US01";

      }

      else if ((this.getField("SubBrand").value == "Adventure" || "Liquid" || "Silver") && (this.getField("Location").value == "WH")) {

          event.value = "WH01";

      }

      elseevent.value = "";
        • 1. Re: Having trouble with if else when used with event.value... please help
          try67 MVP & Adobe Community Professional

          This is not a valid construction:

          if (this.getField("SubBrand").value == "Adventure" || "Liquid" || "Silver")

           

          You need to use something like this:

          var subBrand = this.getField("SubBrand").value;

          if (subBrand == "Adventure" || subBrand == "Liquid" || subBrand == "Silver")

          • 2. Re: Having trouble with if else when used with event.value... please help
            Damian__c Level 1

            Thanks for the tip GIlad I've amended my code but am still experiencing the issue, im at a loss as to what is preventing the address field from changing when the subbrand changes.

            Can you suggest anything else that may be preventing this from happening?

             

            Updated Code:

             

            var subBrand = this.getField("SubBrand").value

            var location = this.getField("Location").value

             

             

            if      ((subBrand == "Passion" || "Passion for Men") && (location == "WW")) {

                    event.value = "Not Applicable";

            }

            else if ((subBrand == "Passion" || "Passion for Men") && (location == "US")) {

                    event.value = "US02";

            }

            else if ((subBrand == "Passion" || "Passion for Men") && (location == "WH")) {

                    event.value = "WH02";

            }

            else if ((subBrand == "Adventure" || "Liquid" || "Silver") && (location == "WW")) {

                    event.value = "WW01";

            }

            else if ((subBrand == "Adventure" || "Liquid" || "Silver") && (location == "US")) {

                    event.value = "US01";

            }

            else if ((subBrand == "Adventure" || "Liquid" || "Silver") && (location == "WH")) {

                    event.value = "WH01";

            }

            else    event.value = "";

            • 3. Re: Having trouble with if else when used with event.value... please help
              try67 MVP & Adobe Community Professional

              The problem was not the use of the variable. I just used it to make the code simpler. The problem was that you can't use the OR operator (or any other operator) like that. Each condition has to be fully written-out. Examine the code above more carefully.

               

              Also, I suggest looking for some core-JS tutorials, like this one: JavaScript Tutorial (ignore the browser-specific parts and focus on the core JS objects)

              • 4. Re: Having trouble with if else when used with event.value... please help
                Damian__c Level 1

                Ahhhhh, I see it now... apologies im getting a bit code blind.

                Thats solved the problem on my stripped down test form, i'll update the real thing now.

                 

                Many Thanks for your advice Gilad