Skip to main content
Inspiring
December 17, 2019
解決済み

Conditional fee calculation in document level javascript

  • December 17, 2019
  • 返信数 18.
  • 1635 ビュー

Hi, I'm trying to create a document-level javascript to calculate three fields with conditions. The three fields are "LicenseFee", "ServiceFee", and "Total". The "LicenseFee" is the only one not read-only; the other two fields will autocalculate based on the number entered in "LicenseFee".

 

I'd like the behavior to go as follows: when "LicenseFee" is empty, "ServiceFee" and "Total" are also empty. When an integer is entered in "LicenseFee" (for example, 120.00), "ServiceFee" will multiply that number by .025 and add 2.00. "Total" will then add "LicenseFee" + "ServiceFee".

 

This what I have so far - up front I am a novice to javascript:

 

function FeeCalc()

{

var Licensefee = this.getField("LicenseFee").value

var ServiceFee = this.getField("ServiceFee").value

var Total = this.getField("Total").value

 

if (LicenseFee='') {

Service='';

Total='';

}

else

{

ServiceFee=(LicenseFee * .025) + (2.00);

Total=LicenseFee + ServiceFee;

}

}

 

I appreciate any and all assistance! Thanks so much! Bill

このトピックへの返信は締め切られました。
解決に役立った回答 wtripoli

Place it as the custom calculation script of a (hidden) text field.


That worked! Thank you so much for your help!

返信数 18

try67
Community Expert
Community Expert
December 17, 2019

In addition to the correct remarks above, be aware that your code doesn't actually change the value of any field.

To do so you have to apply the variable directly to the value property of the fields at the end of it, like this:

this.getField("ServiceFee").value = ServiceFee;

this.getField("Total").value = Total;

wtripoli作成者
Inspiring
December 17, 2019

Thanks, I'm not clear where you're saying those lines should go - into the ServiceFee and Total fields respectively? Do they go into one of the Calculate or Validate text boxes under the field properties?

try67
Community Expert
Community Expert
December 17, 2019

Into the code you posted above, at the end of the function.

bebarth
Community Expert
Community Expert
December 17, 2019

Hi,

In a first step, try with:

...

if (LicenseFee=='') {

ServiceFee='';

...

@+

wtripoli作成者
Inspiring
December 17, 2019

Thanks!