Copy link to clipboard
Copied
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.
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;
Copy link to clipboard
Copied
What if neither of them is ticked? What if only checkbox11 is ticked?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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;
Copy link to clipboard
Copied
that's perfect, thanks!!