2 Replies Latest reply on May 25, 2011 8:02 AM by gkaiseril

    Script for calculations using checkboxes in PDF form

    isabeldelgado

      I have 7 checkboxes, at least one must be checked, but the user may select all. Each one has a value of 800, therefore selecting all seven would give a total of (800 + 800 + 800 + 800 + 800 + 800 + 800). Selecting only two: (800 + 800), etc.

       

      However, the last checkbox is a 50% discount for students.

       

      I'd like the total to have this formula:

      (CheckBox1 + CheckBox2 + CheckBox3 + CheckBox4 + CheckBox5 + CheckBox6 + CheckBox7) = x

      If CheckBox8 is selected, then x/2.

       

      I've done (CheckBox1 + CheckBox2 + CheckBox3 + CheckBox4 + CheckBox5 + CheckBox6 + CheckBox7) / CheckBox8

      but in this way, I only get a value if the CheckBox8 discount is selected. Not everyone will be a student.

       

      Excel, Access, no problem, but I'm new to javascript and pdf forms. Any suggestions?

       

      Isabel

        • 1. Re: Script for calculations using checkboxes in PDF form
          isabeldelgado Level 1

          I think I figured it out:

          I did a simple add into a text field "Modulos" (CheckBox1 + CheckBox2 + CheckBox3 + CheckBox4 + CheckBox5 + CheckBox6 + CheckBox7)

          I set the value of CheckBox8 (which determined whether the person is a student or not) to 1.

          In the Total text field:

           

          if (this.getField("CheckBox8").value=="1") {event.value = this.getField("Modulos").value * 0.5;} else event.value = this.getField("Modulos").value;

          • 2. Re: Script for calculations using check boxes in PDF form
            gkaiseril MVP & Adobe Community Professional

            Two things about Acrobat JavaScirpt and forms you should be aware of:

             

            1. Check boxes and radio boxes have a string value of "Off" when there is no selection is made for the field or a field within an exclusionary group of fields, fields with the same name but different export values.

             

            2. One can not divide by zero and expect a reasonable answer. You will get a string returned with a value of "NaN' (Not a Number), "Infinity", or "-Infinity". Those values maybe number types but the numeric field type can not display them and reports a format error. You can check this by setting the field format to 'None'.