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

If a checkbox is selected can it perform a calculation?

Guest
May 27, 2016 May 27, 2016

Copy link to clipboard

Copied

I would like to have a check box field and if selected it would return a value in another field. Eg. if selected take the value in field "subtotal" and multiply it by 0.05. return that value in field "GST". Is this possible.

TOPICS
Acrobat SDK and JavaScript

Views

410

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 ,
May 27, 2016 May 27, 2016

Copy link to clipboard

Copied

Yes, but it's better to do it from the calculation event of the target field ("GST") then from the check-box itself.

What should be the value of this field if the box is not ticked, though?

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
Guest
May 27, 2016 May 27, 2016

Copy link to clipboard

Copied

The value would be $0.00

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 ,
May 27, 2016 May 27, 2016

Copy link to clipboard

Copied

OK, then use this code as the custom calculation script (you'll just need to adjust the names of the fields involved to match the actual names in your file):

var subtotal = Number(this.getField("subtotal").value);

event.value = (this.getField("CheckBox1").value=="Off") ? 0 : subtotal * 0.05;

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
Guest
May 27, 2016 May 27, 2016

Copy link to clipboard

Copied

Sorry, I am not very familiar with code. Am I pasting the code into the custom calculation script of the GST field? I did and the field names you used are exactly what mine are titled (GST, Subtotal and CheckBox1) but when I check CheckBox1 nothing happens and the GST field does not return a value.

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 ,
May 27, 2016 May 27, 2016

Copy link to clipboard

Copied

LATEST

Yes, that's basically it, but be aware that JS is case-sensitive. So if the field is called "Subtotal" and in the code you have "subtotal" it won't work. You should also check the JS Console (Ctrl+J) for any error messages.

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