1 Reply Latest reply on Apr 14, 2014 11:42 PM by George_Johnson

    Usinga a text combo box and if esle statements to add a calculated result or integer to a field


      I am trying to do what I find easy to do in Excel and that is look up a text field and dependant on the value calculate or insert an integer into another field.   I have tried several combinations but keep getting "Syntax Error: missing ( before condition 1: at line 3."


      I want to look up a text string in a field called "Combo1" and dependant on the selected text from the drop down list to run 3 different variations from a calculation to inserting a fixed value into a field called "ServiceFee".


      The first condition is to insert a value in the "ServiceFee" that is calculated by the sum of 3 fields, and dividing it by 100 multiplying it by 12.5 and then 1.1 to get a value including GST. 


      The other variants in if else statements are insert a fixed value in the "ServiceFee" field.   The other fileds in the form are simple clacs and work well. 


      It is this calculation that I am having difficulty with. I am not sure of the settings for the combo box are the issue or its jyst the script.  The following is one of the scripts that I found on the internet, but this does not work.



      Java - Combo Box lookup.PNG

      Can anyone provide some clarity around the settings of the fileds and the script to run to do some basic calculations.

        • 1. Re: Usinga a text combo box and if esle statements to add a calculated result or integer to a field
          George_Johnson MVP & Adobe Community Professional

          That's not really JavaScript. Assuming this is is supposed to be a custom calculation script for the ServiceFee field, it should be something like:



          // Get the value of the selected combo box item

          var cb_val = getField("Combo1").value;


          // Set this field's value based on the selected item

          switch (cb_val) {

          case "12.5% Fee" :

              event.value = 12.5 * 1.1 / 100 * (+getField("AmountExGST").value + +getField("AmountExGST_2").value + +getField("AmountExGST_3").value);


          case "Flat Fee" :

              event.value = 33;


          case "No Fee" :

              event.value = 0;


          default :

              event.value = 0;




          This doesn't take into account what you should be rounding the values to, which are apparently monetary values. To round to the nearest penny/cent, you'd do something like:


          // Calculate value and round to nearest cent

          event.value = util.printf("%.2f", 12.5 * 1.1 / 100 * (+getField("AmountExGST").value + +getField("AmountExGST_2").value + +getField("AmountExGST_3").value));


          I don't know whether that's an the correct rounding scheme for your application though.