Skip to main content
patrickb81328365
Participant
June 2, 2016
Answered

Javascript with minimum fee schedule- Please HELP!

  • June 2, 2016
  • 2 replies
  • 850 views

Hello,  I am trying to figure out a JavaScript that will auto calculate the fee but will result a minimum fee.

Here is an example:

I have total project cost field (times) the .008 figured out, but will like to go a step further and when that number is below $50, then $50 appears in the last field. When the number is over $50, then the number shows. Example would be $10000 project will auto calculate and show $80.

Anybody know how to do a quick javascript for this scenario?

Thanks,

Patrick

This topic has been closed for replies.
Correct answer try67

Sure, it will be something like this (you might need to adjust the field names involved):

var result = Number(this.getField("total project cost").value) * 0.008;

event.value = Math.max(50, result);

2 replies

patrickb81328365
Participant
June 21, 2016

Try67

Is there a way to have the balance show zero if nothing is entered in the above lines? The min fee and the highest fee work great, but we like to show $0.00 if no one enters a number and just prints the form off. Right now if you just print the form off the min. fee shows up and may not be the case if someone prints it off and fills it by hand...

Thanks for any help!

try67
Community Expert
Community Expert
June 21, 2016

Change it to this:

var result = Number(this.getField("total project cost").value) * 0.008;

if (result==0) event.value = "";

else event.value = Math.min(Math.max(50, result), 185000);

try67
Community Expert
Community Expert
June 2, 2016

Are you currently doing the calculation using JS? If so, post your code.

Basically it can be done like this (assuming the calculated value is stored in the "result" variable):

event.value = Math.max(50, result);

patrickb81328365
Participant
June 2, 2016

Thanks for the reply,

I am not using JS currently, I have the fee automatically calculated by using the text table calculate feature in Adobe pro  but it seems I need a script to get what I am looking to do. Not sure if you can help guide me.

Patrick

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
June 2, 2016

Sure, it will be something like this (you might need to adjust the field names involved):

var result = Number(this.getField("total project cost").value) * 0.008;

event.value = Math.max(50, result);