9 Replies Latest reply on Aug 8, 2016 6:49 AM by emilym88866341

    Hello! Pre-filled Form Questions

    emilym88866341

      Hello!

       

      I am very new at using Adobe and I am trying to make a pre-filled interactive adobe form. I have the boxes communicating/calculating from each other.

      For example I have a Fahrenheit box which has a Celsius box that calculates from the answer entered in the Fahrenheit box. The problem I am having is when Fahrenheit is not applicable during certain uses of the form, the Celsius box is still answering  -17.8° which is equal to 0°F, which the form is assuming is the answer since nothing has been typed in. I need the box to not compute when don't have an answer to enter in.

       

      Can anyone let me know the best solution for my problem?

       

      Thank you!

        • 1. Re: Hello! Pre-filled Form Questions
          gkaiseril MVP & Adobe Community Professional

          First, stop an think about this. What is the numeric value of a null string or mull?

           

          Many programs treat as zero. And this is exactly what JavaScript does if left to itself.

           

          Fortunately most computer languages and scripting languages have conditional statements and some properties, statements or methods that tell the difference between a null string and zero. This type of coding requires custom JavaScript coding.

           

          I assume you do not want to suppress zero results.

           

          For the Celsius box (text field) you need to create a custom JavaScript calculation that uses the conditional "if" statement to test if the Fahrenheit field entry is a null string and not zero.

           

          / default  Celsius result to null sring;

          event.value = "";

          // get field object for Fahrenheit field;

          var oFahrenheit = this.getField("Fahrenheit");

          // test if field value string is null;

          if(oFahrenheit.valueAsString != "")

          {

          // compute conversion only if Fahrenheit value not null;

          event.value = (oFahrenheit.value - 32)  * 5 / 9;

          } // end of value not null;

          • 2. Re: Hello! Pre-filled Form Questions
            emilym88866341 Level 1

            Hello,

             

            Thank you for your response, I just have a couple other questions. When I put your suggestion in my custom calculation form it gives me:

            SyntaxError: unterminated regular expression literal

            1: at line 2

             

            This is the code I had in the box previous to your suggestions in case that helps to figure out the issue :

             

            function calculateCelsius(){

                return (this.getField("Flash_Point_F").value - 32) * 0.5555;

            }

            event.value = calculateCelsius();

             

            Also I call my Fahrenheit box "Flash_Point_F" and I call my Celsius box " Flash Point (C)

             

            If you could give a suggestion as to where to go from here I would really appreciate it!

            • 3. Re: Hello! Pre-filled Form Questions
              try67 MVP & Adobe Community Professional

              The error message must be coming from something else. That script works fine.

              • 4. Re: Hello! Pre-filled Form Questions
                emilym88866341 Level 1

                Do you have any idea what the error message could be coming from? I copied and pasted the exact script.

                • 5. Re: Hello! Pre-filled Form Questions
                  try67 MVP & Adobe Community Professional

                  Probably from an incorrect use of the "/" symbol.

                  • 6. Re: Hello! Pre-filled Form Questions
                    try67 MVP & Adobe Community Professional

                    I think I see the problem.. In the code above there's a missing "/" in the beginning of the first line.

                    • 7. Re: Hello! Pre-filled Form Questions
                      try67 MVP & Adobe Community Professional

                      (I was testing your code before, not the one provided by George...)

                      • 8. Re: Hello! Pre-filled Form Questions
                        gkaiseril MVP & Adobe Community Professional

                        The first line should start with "//"  not "/".

                         

                        if I were to write this as a function, I would pass the degrees Fahrenheit as a parameter and not access the field within the function. That would make the code independent of any fields and it could be used any time when this conversion is needed in other forms. The function definition would be placed at the document level so  its scope would be the entire form. You then  only need 5 lines in the custom calculation script option. I also used the fraction to avoid any issues because of a truncated decimal value.

                         

                        function DF2C(nFerienht)
                        {
                        return (nFerienht - 32) * 5/9;
                        } // end DF2C function;

                         

                        // custom calculation script;
                        var oFlashPoint = this.getField("Flash_Point_F");
                        event.value = "";
                        if(oFlashPoint.valueAsString != "") {
                        event.value = DF2C(oFlashPoint.value);
                        }

                        • 9. Re: Hello! Pre-filled Form Questions
                          emilym88866341 Level 1

                          Yes!!! That worked! Thank you so much I have been working on this for a while now

                           

                          Have a great day!