4 Replies Latest reply on Jan 30, 2013 6:58 PM by fousthvk

    If Else Issue

    fousthvk Level 1

      New to Javascript. This is super simple and I cant figure out why this wont work.

       

      var varPL = this.getField("PLCode").value

       

      if (varPL = "PL1") {

          event.value = ( 'Cedar Discovery' );

      } else {

          event.value = ( 'Structure HIS 12ft only' );

      }

       

       

       

      I have a drop down with Values. I simpley want to check those values and set another field based on the first fields contents. This is set as a calculation in the second field that is trying to be set based on what you choose from field1. Nomater what it only sets the text field to 'Cedar Discovery'

       

       

      Please any help is appreciated.

        • 1. Re: If Else Issue
          fousthvk Level 1

          Finally Figured it out added === after event.value

          • 2. Re: If Else Issue
            George_Johnson MVP & Adobe Community Professional

            That shouldn't have done it, but this should:

             

             

            var varPL = this.getField("PLCode").valueAsString;

             

            if (varPL === "PL1") {

                event.value = "Cedar Discovery";

            } else {

                event.value = "Structure HIS 12ft only";

            }

            • 3. Re: If Else Issue
              fousthvk Level 1

              Your right your right. That's what I did. Too many Sammy adams makes for poor programming.

              • 4. Re: If Else Issue
                fousthvk Level 1

                George, You seem to have all the answers I need a quick fix on the project I am working on. I hope you can help. I am trying to set 3 drop down lists with the same values from a last list. I can get it to se one field but if I add an additional line to the code and call out that field I get a syntax error.

                 

                Here is the code.

                 

                 

                var plCode = {

                                       PL1: [ ["-"], ["Double 7"], ["Triple 5"], ["Half-Round"],["Hand-SplitShake"]],

                                       PL2: [ ["-"], ["Double 6"], ["Single 7"], ["Double 4"],["Double 4.5 DL"]],

                                     };       

                 

                function SetProductLine()

                {

                   if(event.willCommit)

                   {

                      var boName = event.target.name.split(".").shift();

                 

                 

                 

                      var lst = plCode[event.value];

                 

                      if( (lst != null) && (lst.length > 0) )

                         this.getField(boName + ".Row1_ProfileName").setItems(lst);

                         this.getField(boName + ".Row2_ProfileName").setItems(lst);

                         this.getField(boName + ".Row3_ProfileName").setItems(lst);

                      else

                         this.getField(boName + ".Row1_ProfileName").clearItems();

                         this.getField(boName + ".Row2_ProfileName").clearItems();

                         this.getField(boName + ".Row3_ProfileName").clearItems();

                   }

                }

                 

                 

                After the else works but after the IF statement I cannot have more then one line. If I close it in {} it allows me to use it but only seems to repect line one after the IF statement.