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

Custom Calculation on a form

New Here ,
Apr 11, 2018 Apr 11, 2018

Copy link to clipboard

Copied

I am trying to write a custom calculation that adds 3 percent to a specified total when over 500 dollars if a credit card number appears in a field at the bottom of the form

TOPICS
Acrobat SDK and JavaScript

Views

295

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 , Apr 13, 2018 Apr 13, 2018

OK. Let's say the name of the CC field is "CC". In that case, use this code as the custom calculation script of "Grand total".

var total = Number(this.getField("total with freight").valueAsString);

if (this.getField("CC").valueAsString=="") event.value = total;

else event.value = total * 1.03;

Votes

Translate

Translate
Community Expert ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

Is this a PDF form, created in Acrobat?

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 ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

yes, this is a pdf form created in Acrobat

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 ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

OK, I'm going to move your question to a more relevant forum: JavaScript

Can you describe the exact conditions in which you want this calculation to take place?

Is it when the value of one field is more than 500, AND a different field (the CC number) is not empty?

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 ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

Correct

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 ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

here is the scenario

total before freight

freight

total with freight

grand total

The grand total should be the total with a 3% up charge if the credit card field at the bottom of the form is complete

if not complete then should display same as total w freight

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 ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

OK. Let's say the name of the CC field is "CC". In that case, use this code as the custom calculation script of "Grand total".

var total = Number(this.getField("total with freight").valueAsString);

if (this.getField("CC").valueAsString=="") event.value = total;

else event.value = total * 1.03;

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 ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

Thank you.

var total with all = Number(this.getField("total with freight").valueAsString);

if (this.getField("Card#").valueAsString=="") event.value = total with all;

else event.value = total with all * 1.03;

I got a syntax error: ; missing before statement 1 at line 2

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 ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

You can't include spaces in the name of a variable.

On 13 April 2018 at 23:55, charlenen64197186 <forums_noreply@adobe.com>

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 ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

You did not copy the provided code as provided.

Variable names cannot contain spaces.

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 ,
Apr 13, 2018 Apr 13, 2018

Copy link to clipboard

Copied

LATEST

I copied it, but attempted to use the correct names for the fields and put in spaces.  Not a problem thank you.

I will try on Monday.  leaving for the day.

I appreciate the 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