6 Replies Latest reply on Mar 2, 2012 7:11 AM by ioanah1503

    Form Calculations

    ioanah1503 Level 1


      I'm finally wrapping up this form when i came to the conclusion that i cant figure out how to do these javascript calculations . If a knowledgeable person could please help me with this, it would be much appreciated.

      I need the miles field to default to 0.00 mi, tolls, parking, other, total for this trip and amount to be received by employee fields to default to $0.00

      The total for this trip field should calculate = amount entered by user in miles multiplied by 0.555  + amount in tolls+ amount in parking+amount in other

      0.555 is the $/mile amount


      amount received by employee= total for this trip fields added (the user may add as many of these sections as they need so there can be multiple total for this trip fields.


      This is the form:https://acrobat.com/?i=n*E*io*Bm2-UPFLKz-L-Zg

      I used LiveCycle ES 8.2



      i dont know what i'd do with out adobe forums...

        • 1. Re: Form Calculations
          Niall O'Donovan Level 7



          Here is your form: https://acrobat.com/#d=NaiEoId*Icl4XM5p0-ipWw.


          I am also make a few recommendations on layout, spacing and font alignment. I have made the two subforms positioned, as they do not contain expanding objects. The form still flows.


          Hope that helps,



          1 person found this helpful
          • 2. Re: Form Calculations
            ioanah1503 Level 1

            Thank you so much for your help. I just have two more concerns: the amount received by employee is not adding the totals for each trip; nothing is showing up in there. And, the purpose field is set to expand to fit as much text as needed, but now it's flowing over the line below which contains miles, tolls, etc.


            You're the best!

            • 3. Re: Form Calculations
              Niall O'Donovan Level 7

              Try this for size: https://acrobat.com/#d=NaiEoId*Icl4XM5p0-ipWw. Look at the hierarchy for a mixture of positioned and flowed subforms.


              Also the calc in the Total.



              • 4. Re: Form Calculations
                ioanah1503 Level 1


                I am still struggling with this delete section button. Can you please help me. It's only deleting the line it's on now "section2", instead of the entire "details" section. There's also three fields that are telling me they have misspelled words in them. When it says that, where should i look for the spelling error: in the script code ?



                Thank you again,


                • 5. Re: Form Calculations
                  Niall O'Donovan Level 7



                  Here is the form back to you: https://acrobat.com/#d=Nm2jjpCvBeW9w-T4mXtuWA.


                  The issue is that the details part was split into different sections and the references in the script had to be changed to reflect this.


                  Also the spell checker does not check script, only text in form objects:


                  Parallels Desktop.png


                  Hope that helps,



                  1 person found this helpful
                  • 6. Re: Form Calculations
                    ioanah1503 Level 1

                    Hi Niall,

                    I took a stab at placing the submission script below in the submit button of my form and when it's done and saved and re-opened as a PDF, if you click submit, it does pop up with the javascript window asking you if you want to use your default mail client (in our case outlook) but if i hit ok in that window nothing else happens. The goal is that the person clicks submit and an outlook new message pops up with the filled form attached and the to field pre-populates with my email: ioana.hartz@umassmed.edu

                    I really like the idea they suggest here, to have the option of saving a "flattened" copy of the filled in form to your computer.

                    Your help is unimaginably appreciated.




                    Re: Saving Fillable Form as non-fillable PDF

                    Another very simple (less advance) approach would be to make the ENTIRE form protected, readOnly, nonInteractive, etc. by using the following script:


                    xfa.form.form1.access = "protected";



                    In my situation (if this helps anyone), all I wanted to do was enable my user to click an email button to auto-attach a copy of his/her form to an outgoing email, BUT prior to sending the email, I wanted the form to be flattened (i.e. protected). After the email was sent, I wanted it return back to it's open state. So what I did was create a custom email submit button, and added very simple scripts for the preSubmit and postSubmit events. NOTE: This assumes your user is using an email client which will auto-generate an outgoing email (vs. using an Internet email service like GMAIL). If you're using an interent email service, the follwoing scripts will work.



                    1. Email button: This custom email button script allows me to set the subject, body message, to/cc fields, etc. and email the entire form (wth proper Rights) to a given recipient(s).


                    Placed on a standard button's click event:


                    var choice = xfa.host.messageBox("Press OK to submit this form using your default email client (e.g. Microsoft Outlook, Outlook Express, Eudora, Mail, etc.). Note: A copy of this form will be automatically attached to your email. \n\nPress Cancel if you currently use an Internet email service such as Gmail, Hotmail, or Yahoo to send email. You will need save this form on your computer and then manually attach it to an outgoing email (using your Internet email service) addressed to: sample@email.com", " ", 3, 1);


                    // Note: the above text was taken directly from the typical email submit button text. This gives you a way to modify the text if you want.


                    if (choice == 1){

                    var mail;

                    var address = "email@email.com";

                    var ccadd = ccAdd.rawValue; //taken from a field placed on the form

                    var sub = "Subject goes here";


                    var body = "See attatched file.";


                    mail = "mailto: " + address + "?cc=" + ccadd + "&subject=" + sub + "&body=" + body;


                    cURL: mail,

                    bEmpty: true,

                    cSubmitAs: "PDF",

                    cCharset: "utf-8"











                    2. Script added to same email button (created above) to "Protect" ALL form fields PRIOR to the form being emailed. Place on preSubmit event:


                    xfa.form.form1.access = "protected";



                    3. Script added to same email button (created above) to "reopen" ALL form fields AFTER it the form has been submitted. Place on postSubmit event:


                    xfa.form.form1.access = "open";


                    From there, the user can save/SaveAs the original file (currently opened on-screen, with active fields), knowing that he's sent a protected copy. Please note that you've sent a "form" with protect fields...it's still a form, vs a truly "flattened copy".  So if security is a major concern, you'd probably want to use a different approach: for example, a digital signature to track from integrity, or print to PDF. Also, this assumes you;re not concerned with tracking "mandatory fields" etc.



                    As an alternate Step 3, you could interject a SaveAs script on the postSubmit event [ app.execMenuItem("SaveAs") ] to allow your user to save a copy of the protected file somewhere on his/her computer after emailing it. Then he/she could simply cancel the current form (on-screen) - without saving it. This assumes you are not concerned with saving an "open field" version with completed data.




                    Hopes this helps someone!