Skip to main content
Participant
June 20, 2023
Question

calculating total when checkboxes unchecked

  • June 20, 2023
  • 2 replies
  • 382 views

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 

This topic has been closed for replies.

2 replies

try67
Community Expert
Community Expert
June 20, 2023

- 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.

Liv2xAuthor
Participant
June 20, 2023

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