1 Reply Latest reply on Jan 6, 2017 5:47 AM by try67

    Javascript Calculation Dependent on which Checkbox is Checked

    thomasm3635628

      I am trying to create javascript to populate a field (FieldText13) with a dollar amount based upon whether or not CheckBox9 (2 hours) or CheckBox11 (4 hours) is checked multiplied by the dollar amount that is entered by the user in FieldText11.

       

      I've made multiple attempts but cannot get the javascript to work. 

       

      Thank you.

       

      var cb1 = this.getField("CheckBox9").isBoxChecked(0);
      var cb2 = this.getField("CheckBox11").isBoxChecked(0);

      if (cb1 && cb2) {
          event.value = "";
      }
      else if (cb1) {
          event.value = ("FillText09" * "FillText09val");
      }
      else if (cb2) {
          event.value = ("FillText11" * "FillText11val");
      }
      else {
          event.value = "";

      }

        • 1. Re: Javascript Calculation Dependent on which Checkbox is Checked
          try67 MVP & Adobe Community Professional

          First of all, if those check-boxes are mutually exclusive then you should set them up like that. You can do so by giving them the same name but different export values.

           

          Regarding your script: To access the value of a field you must use the getField method and then the value property, not just write out the field's name. So instead of this:

          event.value = ("FillText09" * "FillText09val");

          Use this:

          event.value = this.getField("FillText09").value * this.getField("FillText09val").value;

          1 person found this helpful