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!
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 + "'");
Copy link to clipboard
Copied
To compare the value of variable a use == not =
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.
Copy link to clipboard
Copied
You can display the value in the console:
console.show();console.println(a);
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.
Copy link to clipboard
Copied
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 + "'");