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

calculation based on checkbox and another calculated field

New Here ,
Aug 22, 2018 Aug 22, 2018

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

485

Translate

Translate

Report

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

correct answers 1 Correct answer

Community Expert , Aug 22, 2018 Aug 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;

Votes

Translate

Translate
Community Expert ,
Aug 22, 2018 Aug 22, 2018

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

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 ,
Aug 22, 2018 Aug 22, 2018

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.

Votes

Translate

Translate

Report

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 ,
Aug 22, 2018 Aug 22, 2018

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;

Votes

Translate

Translate

Report

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 ,
Aug 22, 2018 Aug 22, 2018

Copy link to clipboard

Copied

LATEST

that's perfect, thanks!!

Votes

Translate

Translate

Report

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