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

Base rate plus tick box

Community Beginner ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

Hi All,

Please forgive my ignorance in Java - I am attempting to create a calculated field which has a base value, then if a tickbox is checked, add X to the base rate (this needs to work for multiple checkboxes); what I have so far:

event.value = 0.07;

if(checkBox1.rawValue==true)

{event.value+0.015}

if(checkBox2.rawValue==true)

{event.value+0.05}

this needs to be additive so if (for example) tickbox 1,4,6 and 8 are ticked, all their denoted values will be added to the base rate.

Example:

tickbox 1 = 0.015

tickbox 4 = 0.05

tickbox 6 = 0.02

tickbox 8 = 0.01

textbox = 0.07+0.015+0.05+0.02+0.01

any help would be greatly appreciated!

Regards

TOPICS
Acrobat SDK and JavaScript

Views

593

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

Sure, it can be done, but your code was written for an LCD form, which is why we wanted to make sure what kind of form you have.

You can use something like this as the custom calculation script of the field where you want to show the total value:

var v = 1.24; // base value

if (this.getField("tickbox 1").valueAsString!="Off") v+=0.015;

if (this.getField("tickbox 4").valueAsString!="Off") v+=0.05;

// etc.

event.value = v;

Votes

Translate

Translate
LEGEND ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

This question would be best in the LiveCycle Designer forum, so I'll move it there for you: LiveCycle Designer

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 Beginner ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

I am not using LiveCycle Designer - are you saying that it cannot be done with normal Adobe X Pro calculated form field?

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

Copy link to clipboard

Copied

Sure, it can be done, but your code was written for an LCD form, which is why we wanted to make sure what kind of form you have.

You can use something like this as the custom calculation script of the field where you want to show the total value:

var v = 1.24; // base value

if (this.getField("tickbox 1").valueAsString!="Off") v+=0.015;

if (this.getField("tickbox 4").valueAsString!="Off") v+=0.05;

// etc.

event.value = v;

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 Beginner ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

Awesome, works like a bomb! thanks Try67!

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 Beginner ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

So my joy was short-lived due to the form needing to be filled out in the field - meaning that for most users, JavaScript custom calcs are disabled for iPads et al. is there any way to write this as a basic math equation using the simplified notation?

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
LEGEND ,
Aug 28, 2018 Aug 28, 2018

Copy link to clipboard

Copied

All of the calculation options rely on JavaScript, you just don't see it with the first two options. So if the PDF viewer doesn't have sufficient support for JavaScript, there's nothing you can do.

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 Beginner ,
Aug 28, 2018 Aug 28, 2018

Copy link to clipboard

Copied

The simplified field notations to calculate other fields with math formulas work fine, it is just the custom script done above that doesn't work.

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

Copy link to clipboard

Copied

You can try this: Apply the value associated with each check-box as its export value and then use the Simple Field Notation option to simply add up all of those fields, plus the base value (which you can hard-code into the formula as a number or place into a hidden field and then add that field to the sum).

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 Beginner ,
Aug 28, 2018 Aug 28, 2018

Copy link to clipboard

Copied

LATEST

Try67 with the win once again! nicely done. thanks very much for your help!

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
LEGEND ,
Aug 27, 2018 Aug 27, 2018

Copy link to clipboard

Copied

If you're creating the form in Acrobat instead, let me know and I'll move it back to the Acrobat JavaScript forum.

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