Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

calculating total when checkboxes unchecked

New Here ,
Jun 20, 2023 Jun 20, 2023

alright so here is my code, i know it looks crude but its the best ive gotten so far:

 

if(this.getField("B1").isBoxChecked(0) && this.getField("L1").isBoxChecked(0) && this.getField("D1").isBoxChecked(0))
this.getField("D1T").value = this.getField("Breakfast").value + this.getField("Lunch").value + this.getField("Dinner").value

else if(this.getField("B1").isBoxChecked(0) && this.getField("L1").isBoxChecked(0) || this.getField("L1").isBoxChecked(0) && this.getField("B1").isBoxChecked(0))
this.getField("D1T").value = this.getField("Breakfast").value + this.getField("Lunch").value

else if(this.getField("B1").isBoxChecked(0) && this.getField("D1").isBoxChecked(0))
this.getField("D1T").value = this.getField("Breakfast").value + this.getField("Dinner").value

else if(this.getField("L1").isBoxChecked(0) && this.getField("D1").isBoxChecked(0))
this.getField("D1T").value = this.getField("Lunch").value + this.getField("Dinner").value

else
this.getField("D1T").value = 0

 

Ok so the issue is when the checkboxes are checked the value of each repsect percentage is calculated and totaled into the respective field. However, when you uncheck a box the value does not update ( supose B1 + D1 + L1 are checked,  when B1 is unchecked the total is not updated with the value of D1+L1 instead it just gives me back the default of the total value which is set to 0.) i tried using OR (||) but it just breaks my code making it not calculate at all now 

TOPICS
JavaScript , PDF forms
322
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jun 20, 2023 Jun 20, 2023

Also whenever i box is checked this pops up in the console: TypeError: f is null
1282:byteCodeTool

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 20, 2023 Jun 20, 2023
LATEST

- Where did you place the code?

- The error message suggests you used an incorrect field name somewhere in your calculations, most likely not in a script, but when using the built-in calculation options, or the Simple Field Notation.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines