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

If a checkbox is selected can it perform a calculation?

Guest
May 27, 2016 May 27, 2016

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
484
Translate
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

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?

Translate
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

The value would be $0.00

Translate
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

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;

Translate
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

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.

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

Translate
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