5 Replies Latest reply on Dec 26, 2012 1:45 AM by try67

    kinda if/then/else but more

    m.Rodin

      I three fields that I am working with. First field is a drop down, second is a text field, and third is a read out based on the text field.

       

      If someone picks option 2 of the drop down field and if I have 19 in the txtField I want it to add 2 to the text field making it 21 which would make the read out 5.

       

      Problem I am running into is when I pick the drop down option 2 the txtField changes properly but the read out only goes up by 1 digit and doesn't give the right read out.

       

      I am not sure the syntax to this or which of the fields in the pdf I should put this script into?

       

      I have so far for the drop down:

      if (this.getField("optionTwo").value == 'yes') {

      var Lit = this.getField("txtField");

      event.value = Lit.value+2;

      }

       

      for the Text field Readout:

       

      if (this.getField("txtField").value <= '11') {

      event.value = 0

      } else if (this.getField("txtField").value <= '13') {

      event.value = 1

      } else if (this.getField("txtField").value <= '15') {

      event.value = 2

      } else if (this.getField("txtField").value <= '17') {

      event.value = 3

      } else if (this.getField("txtField").value <= '19') {

      event.value = 4

      } else if (this.getField("txtField").value <= '21') {

      event.value = 5

      } else if (this.getField("txtField").value <= '23') {

      event.value = 6

      } else if (this.getField("txtField").value <= '25') {

      event.value = 7

      } else if (this.getField("txtField").value <= '27') {

      event.value = 8

      } else if (this.getField("txtField").value <= '29') {

      event.value = 9

      } else if (this.getField("txtField").value == '30') {

      event.value = 10

      }

       

        • 1. Re: kinda if/then/else but more
          try67 MVP & Adobe Community Professional

          If you're doing comparisons between numbers, don't place any of them in quotes since then they'll be treated as strings and the results will be wrong.

          Also, it seems to me you can use a simple formula for the second part of the calcluation...

          • 2. Re: kinda if/then/else but more
            m.Rodin Level 1

            Not trying to compair numbers. Could you give me an example of the simple formula for the second part?

            • 3. Re: kinda if/then/else but more
              try67 MVP & Adobe Community Professional

              In a statement like this you're not comparing numbers??

              if (this.getField("txtField").value <= '11') {

              It needs to be:

              if (+this.getField("txtField").value <= 11) {

               

              As for the formula, I think this will do the trick:

              var v = +this.getField("txtField").value;

              event.value = Math.floor((v-10)/2);

              • 4. Re: kinda if/then/else but more
                m.Rodin Level 1

                try67 wrote:

                 

                As for the formula, I think this will do the trick:

                var v = +this.getField("txtField").value;

                event.value = Math.floor((v-10)/2);

                This isn't doing what I am desiring. This is taking value of txtField subtracting 10 then dividing by 2 after that.

                 

                What I'd like for it to do is if Option2 of the drop down is picked to then take what ever I have manually put into the txtField add 2 to it. Then have the read out change accordingly to that new number.

                 

                Example from my old table top role playing days. Player has a 18 dexterity, this gives him/her a 4 ability modifier. Now if player picks a nomad race they get a plus 2 to their dexterit. When the dexterity changes to a 20 the ability modifier will become 5.

                 

                Option2(Nomad Race), txtField(dexterity), txtFieldReadOut(ability modifier)...

                • 5. Re: kinda if/then/else but more
                  try67 MVP & Adobe Community Professional

                  It is doing the same as your set of if-else statements... But if you don't want to, don't use it.