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

Creating Conditional Calculation Script

New Here ,
Oct 12, 2018 Oct 12, 2018

Copy link to clipboard

Copied

Hello.  I'm going to preface my question by admitting up front that I have *zero* knowledge of JavaScript and I have spent the morning searching the web and this forum for answers to my questions but nothing has worked so far.

I'm trying to create a form for my leasing agent (who somehow manages to corrupt my Excel spreadsheet despite password protection AND locked cells) for his leasing commissions.  I have a drop down field called "DealType" where he can choose the options "New Lease / New Tenant", "New Lease / Existing Tenant" or "Lease or Option Renewal".  He then goes along and enters the rent components, which I have subtotaling into a read-only field called "TotalRent".

I want to create a read-only field called "CommissionDue" which would read something like this in Excel-speak:

If DealType="Lease or Option Renewal",TotalRent*50%,TotalRent

Using articles from Thom Parker, I put this script together:

event.value = "";

var a = +this.getField("DealType").value;

var b = +this.getField("TotalRent").value;

if (a="Lease or Option Renewal") event.value = b * 0.50;

else event.value = b;

However it is always putting the value in "CommissionDue" as 50% of the total rent, no matter what I pick for the deal type.

I would appreciate any help in getting over this last hurdle and making the calculation work properly.  Thank you!

TOPICS
Acrobat SDK and JavaScript , Windows

Views

367

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

You can add the lines to your code:

event.value = "";

var a = this.getField("DealType").value;

var b = +this.getField("TotalRent").value;

if (a == "Lease or Option Renewal") event.value = b * 0.50;

else event.value = b;

console.show();

console.println("a: '" + a + "'");

Votes

Translate

Translate
Community Expert ,
Oct 12, 2018 Oct 12, 2018

Copy link to clipboard

Copied

To compare the value of variable a use == not =

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 ,
Oct 12, 2018 Oct 12, 2018

Copy link to clipboard

Copied

I assume you mean change the if line to  if (a=="Lease or Option Renewal") event.value = b * 0.50; else event.value = b;

That creates the opposite result; everything defaults to the full rent.

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 ,
Oct 12, 2018 Oct 12, 2018

Copy link to clipboard

Copied

You can display the value in the console:

console.show();console.println(a);

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 ,
Oct 12, 2018 Oct 12, 2018

Copy link to clipboard

Copied

As I stated at the beginning, I have zero knowledge of JavaScript so I really do not understand what you are trying to say.  While I appreciate the help I need the "dummies" version.

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

Copy link to clipboard

Copied

LATEST

You can add the lines to your code:

event.value = "";

var a = this.getField("DealType").value;

var b = +this.getField("TotalRent").value;

if (a == "Lease or Option Renewal") event.value = b * 0.50;

else event.value = b;

console.show();

console.println("a: '" + a + "'");

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