4 Replies Latest reply on Jun 10, 2014 6:48 PM by New Guy 40

    JS Help

    New Guy 40

      With this script, I am trying to make the statement... IF FamilyMember=3 then Family1 is not diplayed, else Family1 is displayed.  However the following script does not work

       

       

       

      var FamilyMemeber=this.getField("SelectFamily1")

      if(FamilyMember==3)

       

      var Family1 = ""

       

      else

       

       

      var Family1 = this.getField("SelectFamily1").value

      + " " +

      this.getField("FirstName1").value

      + " " +

      this.getField

      ("LastName1").value

      + " " +

      "(Born in"

      + " " +

      this.getField

      ("COB1").value

      + ". " +

      this.getField

      ("Status1").value

      + " DOB: " +

      this.getField

      ("DOB1").value

      + "). ";

       

      var Family2 = this.getField("SelectFamily2").value

      + " " +

      this.getField("FirstName2").value

      + " " +

      this.getField

      ("LastName2").value

      + " " +

      "(Born in"

      + " " +

      this.getField

      ("COB2").value

      + ". " +

      this.getField

      ("Status2").value

      + " DOB: " +

      this.getField

      ("DOB2").value

      + "). ";

       

      event.value = Family1 + Family2;

        • 1. Re: JS Help
          George_Johnson MVP & Adobe Community Professional

          var FamilyMemeber=this.getField("SelectFamily1")

          if(FamilyMember==3)

           

           

          That first line does not get the value of the field, it sets the FamiliyMemeber variable to a field object. It also looks like there's a typo in the field name (Memeber vs Member). You should also use curly braces ({}) in your if/else blocks. Without them, it is unclear which code belongs within the else clause.

          • 2. Re: JS Help
            New Guy 40 Level 1

            Do you have an example code I can use?

            • 3. Re: JS Help
              George_Johnson MVP & Adobe Community Professional

              If I understand your code correctly, I believe it should be something like this:

               

              var Family1 = "";

              var FamilyMember =  getField("SelectFamily1").value;

               

              if (FamilyMember != 3) {

               

                  Family1 = getField("SelectFamily1").valueAsString + " " + 

                            getField("FirstName1").valueAsString + " " +

                            getField("LastName1").valueAsString + " (Born in " +

                            getField("COB1").valueAsString + ". " +

                            getField("Status1").valueAsString + " DOB: " +

                            getField("DOB1").valueAsString + "). ";

              }

               

              var Family2 = getField("SelectFamily2").valueAsString + " " + 

                            getField("FirstName2").valueAsString + " " +

                            getField("LastName2").valueAsString + " (Born in " +

                            getField("COB2").valueAsString + ". " +

                            getField("Status2").valueAsString + " DOB: " +

                            getField("DOB2").valueAsString + "). ";

               

              // Set this field's value

              event.value = Family1 + Family2;

              • 4. Re: JS Help
                New Guy 40 Level 1

                Thanks for you help, I really appreciate it.

                 

                What my code is attempting to do is......

                 

                if FamilyMember !=3 then the value of Family1 =""

                 

                 

                 

                So would this be correct?

                {

                Family1 = getField("SelectFamily1").valueAsString + " " +   

                              getField("FirstName1").valueAsString + " " +

                              getField("LastName1").valueAsString + " (Born in " +

                              getField("COB1").valueAsString + ". " +

                              getField("Status1").valueAsString + " DOB: " +

                              getField("DOB1").valueAsString + "). ";

                }

                 

                 

                var FamilyMember =  getField("SelectFamily1").value;

                 

                if (FamilyMember != 3) {

                 

                    var Family1 = "";}

                 

                var Family2 = getField("SelectFamily2").valueAsString + " " + 

                              getField("FirstName2").valueAsString + " " +

                              getField("LastName2").valueAsString + " (Born in " +

                              getField("COB2").valueAsString + ". " +

                              getField("Status2").valueAsString + " DOB: " +

                              getField("DOB2").valueAsString + "). ";

                 

                // Set this field's value

                event.value = Family1 + Family2;