Skip to main content
qe79015281
Participating Frequently
August 22, 2018
Answered

calculation based on checkbox and another calculated field

  • August 22, 2018
  • 1 reply
  • 770 views

I have a form whereby I need a total to appear based on a checkbox...

eg if checkbox10 is checked then "total1" becomes the total of field "qty1"

if checkbox10 and checkbox11 are checked then "total1" becomes the total of fields "qty1" + "qty2"

been playing with it for a while but can't figure it out.

I'm doing it this way because I need the totals of all the "qty" fields to add up on the form, but also need a total of just the checked "qty" fields in another section of the PDF.

This topic has been closed for replies.
Correct answer try67

You can use this code as the custom calculation script of the total field:

var total = 0;

if (this.getField("checkbox10").value!="Off") total+=Number(this.getField("qty1").valueAsString);

if (this.getField("checkbox11").value!="Off") total+=Number(this.getField("qty2").valueAsString);

event.value = total;

1 reply

try67
Community Expert
Community Expert
August 22, 2018

What if neither of them is ticked? What if only checkbox11 is ticked?

qe79015281
Participating Frequently
August 22, 2018

if only checkbox11 is checked, then "total1" is the total of field "qty2"

if none are checked it doesn't matter because the page that field "total1" is on isn't required.

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 22, 2018

You can use this code as the custom calculation script of the total field:

var total = 0;

if (this.getField("checkbox10").value!="Off") total+=Number(this.getField("qty1").valueAsString);

if (this.getField("checkbox11").value!="Off") total+=Number(this.getField("qty2").valueAsString);

event.value = total;