4 Replies Latest reply on Jan 9, 2013 3:57 PM by heathmcguire

    Custom script help

    heathmcguire

      I have created a form with a dozen fields that have either custom formatting or custom calculations. Six fields are entered by the user and six calculated from those values. A couple of the fields require maximum values. The form looks exactly as I had hoped but I have a math error that has me stumped. 

       

      It works or doesn't as follows:

      Field "G1" is calculated from an above Field and =10 .

      Field "G" is entered by the user =11, it can be no greater than Field "G1".

      Field "H1" is calculated from an above Field and =10.

      Field "H" is entered by the user =11, it can be no greater than "H1"

      Field "I" is the sum of Fields (“G”+“H”)

       

      If the user enters a value in Field "G" greater than "G1" I want the value of "G" to revert to "G1". And the same for "H".

      Ex;

      "G1"=10 and "G"=11

      "H1"=10 and "H"=11

      "I"=20

       

      The form looks as tho it is doing that but it is only changing the appearance of "G" and "H", the math is then off in "I".

      Ex;

      "G1"=10 and "G"=10

      "H1"=10 and "H"=10

      "I"=22

       

      I am out of my league on this and appreciate any assistance.

        • 1. Re: Custom script help
          George_Johnson MVP & Adobe Community Professional

          It's hard to say what's going on without seeing the calculations you set up. If you're using JavaScript to perform the calculations, can you post it here?

          1 person found this helpful
          • 2. Re: Custom script help
            heathmcguire Level 1

            "G1" is calculated from user entered field "D" and I have simplied field notation as:

            (D*0.25)

             

            "G" is entered by the user and I have the Format Script as:

            if(getField("G").value > getField("G1").value) {    

                    event.value = getField("G1").value;

            } else event.value = getField("G").value;

             

            "H1" is calculated from user entered field "D" and I have simplied field notation as:

            (D*0.25)

             

            "H" is entered by the user and I have the Format Script as:

            if(getField("H").value > getField("H1").value) {

            event.value = getField("H1").value;

            } else event.value = getField("H").value;

             

            "I" is calculated and is the sum of entries in "G" and "H"

             

            For the example below I entered 19 in field "G". It displays as the maximum of 18.75 but is calculated as 19 in "I"

            There are other fields on the form that all come together but my issue is with "G" and "H".

            PEC Form.jpg

            • 3. Re: Custom script help
              George_Johnson MVP & Adobe Community Professional

              You're misusing the format event, that is, yo shouldn't put the script there. Use that following Validate event for the G field:

               

              "G" is entered by the user and I have the Format Script as:

               

              // Custom Validate script

              if (+event.value > +getField("G1").value) {    

                      event.value = getField("G1").value;

              }

               

              Do the same for field H. The + in the script above simply converts event.value (which is a string) and the field value (which could return a number or string) to a number. It's a good idea to do this when you're comparing numeric values.

              • 4. Re: Custom script help
                heathmcguire Level 1

                Thank you so much! Worked perfectly and now I understand too.