Skip to main content
Known Participant
August 19, 2020
Question

if A+B>C then A+B=C

  • August 19, 2020
  • 1 reply
  • 995 views

Hello, 

could you please help me to script the following in a pdf form:

if A+B>10 then A+B=10

Thanks

This topic has been closed for replies.

1 reply

BarlaeDC
Community Expert
Community Expert
August 19, 2020

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.

Inspiring
August 19, 2020

The line that reads:

 

var total= fieldA.value + fieldB+value;

 

should be

var total= fieldA.value + fieldB.value;

 

A common typo we all make