Copy link to clipboard
Copied
Hello,
could you please help me to script the following in a pdf form:
if A+B>10 then A+B=10
Thanks
Copy link to clipboard
Copied
Hi,
It would help if we knew the names of the fields you are trying to use ( I will assume they are called 'A', 'C', with the total going into 'C'
var fieldA = this.getField("A");
var fieldB = this.getField("B"):
var total= fieldA.value + fieldB.value;
if ( total > 10 ) {
total = 10;
}
this.getField("C").value = total;
This code could be added to the validation of 'A' and 'B', which would mean it would be run everytime the values changed.
Hope this helps.
Malcolm
edit - to fix typo.
Copy link to clipboard
Copied
The line that reads:
var total= fieldA.value + fieldB+value;
should be
var total= fieldA.value + fieldB.value;
A common typo we all make
Copy link to clipboard
Copied
Thanks Malcolm,
How to add a line to remove any trailing zero from the end of the result?
Copy link to clipboard
Copied
Format field as number.
Copy link to clipboard
Copied
If I format as (None), no trailing zero will appear.
But if I want to allow for 2 decimels without a trailing zero, I think a script has to be added to remove the trailing zero.
(I am a learner and beginner, please bear with me)
Thanks
Copy link to clipboard
Copied
So you wan't if result is 2.22 to show like that but if result is 2.00 to just show 2?
Copy link to clipboard
Copied
correct
Copy link to clipboard
Copied
Hi, try this code and see if it is what you wanted:
var a = this.getField("A").value;
var b = this.getField("B").value;
var x = a+b;
var x1 = x.toFixed(2);
var x2 = x1.replace(".00", "");
event.value = x2;
if( x2 > 10 ){
x2 = 10;
}
event.value = x2;
Don't format field, leave it at "None".