7 Replies Latest reply on Sep 3, 2015 3:29 AM by Bernd Alheit

    Why doesn't a javascript code work completely when I try to hide 0.00?

    jay45807004 Level 1

      I’m having a bit of trouble with one field on a long form.  The pertinent fields are:

       

      PercentWorkCompletedtoDate        (user enters the numbers)

      TotalContractToDate                       (user enters the numbers)

      WorkCompletedtoDate

      StoredMaterial                                 (user enters the numbers)

      TotalCompletedWorkandStoredMaterials

      LessRetainage

       

      The LessRetainage field calculates correctly when I only have the script:

      var TCW = this.getField("TotalCompletedWork&StoredMaterials");

      var Percent = this.getField("PercentWorkCompletedtoDate");

      var Retainage = this.getField("LessRetainage");

      if (Percent.value <=50){ Retainage.value = .05 * TCW.value} else {Retainage.value = .025 * TCW.value}

       

      But when I try to hide the 0.00 in the LessRetainage field until users actually input numbers, the zero is hidden, but the LessRetainage field will not populate until numbers are entered in the StoredMaterial field.  If the StoredMaterial field is left blank or even if a 0 is entered, the LessRetainage field does not populate at all with the following script:

       

      var TCW = this.getField("TotalCompletedWork&StoredMaterials");

      var Percent = this.getField("PercentWorkCompletedtoDate");

      var Retainage = this.getField("LessRetainage");

      if (Percent.value <=50){ Retainage.value = .05 * TCW.value} else {Retainage.value = .025 * TCW.value}

      if (TCW !==0) {event.value = ""}

       

      All the fields are number formats. The LessRetainage field needs to populate whether or not the StoredMaterial field is left blank or a 0 is entered, can anyone help me with this? 

       

      The WorkCompletedtoDate script is:

      var v1 = this.getField("PercentWorkCompletedtoDate").value;

      var v2 = this.getField("TotalContractToDate").value;

      var sum = v1 * v2 / 100

      if (sum !==0) {event.value = sum;} else {event.value = ""}

       

      The TotalCompletedWorkandStoredMaterials script is:

      var v1 = this.getField("WorkCompletedtoDate").value;

      var v2 = this.getField("StoredMaterial").value;

      var sum = v1 + v2

      if (sum !==0) {event.value = sum;} else {event.value = ""}