1 Reply Latest reply on Aug 6, 2011 9:57 AM by gkaiseril

    Calculating sum from a drop box selection



      I am fairly new at using acrobat so please bear with me. I have created a form that includes multiple drop down menus. I would like to summarize the selection of those drop down menus acording by what was chosen for eg. under drop down menu 1 the user selected Assests, under drop down menu 2 user selected Cost, under drop down menu 3 user selected Assests again. I would like to have a text box named Assests which will count how many times did the user select Assests (in the case of the eg. that value should be 2 )  and the same for Cost (in the case of the eg that value should be. 1) .

      I am fairly new in java scripting and i was thinking of something along


      var qty = this.getField("Dropdown_menu1").value;
      var sum = 0;
      If (qty == "Assets") then sum=sum+1;
      event.value = sum;


      Your help is highly appreciated.

        • 1. Re: Calculating sum from a drop box selection
          gkaiseril MVP & Adobe Community Professional

          Your script only test the "Dropdown_menu1" field, you need to repeat it for each drop down field you want to test. If you just copy the script and change the field name you will have a lot of duplicated code. You can make the field name a variable and then change the field being tested by changing the variable name.


          // build an array of field names to test;
          var aMenu = new Array("Dropdown_menu1", "Dropdown_menu2","Dropdown_menu3");
          var count = 0; // count of field names
          // loop through the array of field names one at time;
          for(i = 0; i < aMenu.length; i++) {
          // add 1 if equal else add zero
          count += ("Assets" == this.getField(aMenu[i]).value? 1 : 0);
          event.value = count;