7 Replies Latest reply on May 31, 2015 2:49 PM by johnwohlmut

    can someone help me with the if/else script

    johnwohlmut

      I have an input form field called howmany

      and a form field call Result

      Lets say the form field gets a 2

      I put the following code in the custom calculation property of the Result field

       

       

      var tst=this.getField("howmany");

      if(tst.value>1)

      event.value=tst.value*10;

      else

      event.value=tst.value*5;

       

       

      I cant seem to get any kind of if /else block to work

       

      If somebody could shed some light on what I need to do it would be greatly appreciated.

      I cant seem to find any resources that will explain the syntax for Adobe Acrobat Javascript

       

      I'm using Acrobat Pro DC

        • 1. Re: can someone help me with the if/else script
          George_Johnson MVP & Adobe Community Professional

          The code appears to be syntactically correct. The first step should be to check the JavaScript console to see if any errors are reported. Press command+J to display it. Anything?

          • 2. Re: can someone help me with the if/else script
            try67 MVP & Adobe Community Professional

            The code seems OK. Do you see any error messages in the JS console (Ctrl+J)?

             

            On Sat, May 30, 2015 at 5:23 PM, johnwohlmut <forums_noreply@adobe.com>

            • 3. Re: can someone help me with the if/else script
              johnwohlmut Level 1

              I get no error messages but the if/else block just does not function.

              The event.value does not change.

               

              Very frustrating

              thanks for your help anyway

              • 4. Re: can someone help me with the if/else script
                Test Screen Name Most Valuable Participant

                Is JavaScript enabled (in Preferences)?

                 

                Can you make even a totally simple script work e.g.

                 

                event.value="9999"

                 

                which should test if JavaScript is being used at all.

                 

                You say there is nothing to explain JavaScript, suggests you need to download the Acrobat JavaScript resources, hundreds of pages of introduction and reference (but not sadly a beginner's guide).

                • 5. Re: can someone help me with the if/else script
                  try67 MVP & Adobe Community Professional

                  Can you share the file in question?

                  • 6. Re: can someone help me with the if/else script
                    Karl Heinz Kremer Adobe Community Professional

                    As other's have said already, the syntax of your script looks good. Also, you are not getting any error messages on the JavaScript console, that's also good. One thing to check is to make sure that your script is really a custom calculation script. There are a number of scripts you can add for a form field (custom validation, format, keystroke and calculation scripts). Make sure you are on the "Calculate" tab and that you've selected a custom calculation script.

                     

                    One way to found out what's going on is to insert debug output statements in your code. You can for example use the following:

                     

                    console.println("In custom calculation script");
                    var tst = this.getField("howmany");
                    console.println("got the field: field.value = " + tst.value);
                    if (tst.value > 1) {
                      console.println("tst.value > 1");
                      event.value = tst.value * 10;
                      console.println("set event.value to " + tst.value * 10);
                    } else {
                      console.println("tst.value <=1");
                      event.value = tst.value * 5;
                      console.println("set event.value to " + tst.value * 5);
                    }
                    console.println("done with custom calculation script");
                    
                    

                     

                    You can now follow on the JavaScript console what's going on with your script. Also, make sure that you actually leave the field "howmany" by either tabbing out of it, or by clicking outside of it. The value only gets committed (and therefore other calculation scripts only run) after you leave the field.

                    • 7. Re: can someone help me with the if/else script
                      johnwohlmut Level 1

                      thanks for your help. I copied the script exactly as you suggested.

                      The console,println does not work and i have the debug turned on.

                      The script did not work until I added an app.alert after the first if statement then magically the calculations were performed

                      so I took out the app.alert and ran it again and it worked fine but still no console.println

                       

                      need to do some more research

                       

                      thanks everybody