Copy link to clipboard
Copied
I am trying to create a pdf javaScript formula that calculates if a field is greater than 2 multiple that field's value by 25 but not to exceed $250
Copy link to clipboard
Copied
Use the following custom calculation script:
var fld=this.getField("theField").value;
if(fld>2)
{event.value=fld*25}
else
{event.value=""}
if(event.value>250)
{event.value=250}
Copy link to clipboard
Copied
Use the following custom calculation script:
var fld=this.getField("theField").value;
if(fld>2)
{event.value=fld*25}
else
{event.value=""}
if(event.value>250)
{event.value=250}
Copy link to clipboard
Copied
Consider adding an 'else' condition to reset the field to blank or 0 if the value initially exceeds 2 but subsequently drops below 2.
Copy link to clipboard
Copied
Good point. Answer edited.
Copy link to clipboard
Copied
The order you added them is not correct, though.
It should be if - else if - else.
Copy link to clipboard
Copied
Yes you can do it that way and I usually would, but I made an adjustment to what I already had. My script works. The first if/else statement calculates the value. The next if statement takes that value and adjusts it down to 250 if it is > 250.
Copy link to clipboard
Copied
Thanks, that works perfectly.
Now, I trying to do something similar.
If the value of that field is greater than 2 there's a 5% tax added but if it's greater than 3 there's a 10% tax added.
Copy link to clipboard
Copied
Try this:
var fld = this.getField("theField").value;
var result = 0;
var maxLimit = 250;
if (!isNaN(fld) && fld > 2) {
result = fld * 25;
if (fld > 2 && fld <= 3) {
result = result * 1.05;}
else if (fld > 3) {
result = result * 1.10;}}
event.value = Math.min(result, maxLimit);
Copy link to clipboard
Copied
I guess I misspoken. The formula needs to indicate if the field is greater than 2, the value should be 5% and if the field is greater than 3 the value should be 10%
Copy link to clipboard
Copied
% of what? The result? Use Nesa's script but change 1.05 to .05 and change 1.10 to .1
Copy link to clipboard
Copied
Just ment to determine if the tax value is 5% or 10%. I'm using another field to calculate the value based on that field..
in other words I used the 1st java script to determine "this field " is greater han 2 multiple by 25.
I need new field that calculates if "the field" is greater than 2 the value = .5 and if "the field " is greater than 3 the values = .10.
I'm sorry I made it confusing