Skip to main content
stepheng54012748
Known Participant
December 19, 2017
Answered

I'm trying to come up with a script that would function as an if/then scenario.

  • December 19, 2017
  • 1 reply
  • 723 views

I'm trying to come up with a script that would function as an if/then scenario.  I very new a writing in JavaScript and have done a reasonable job developing an interactive form.  My form has a section where there are 3 lines of information that adds up to a number.  That number can be either a positive or a negative number which would populate in field "l100".  The other field consists of a number that adds up three fields "l37"+"l38"+"l39" which will always be a positive number this populates in field "l41".  "l41" final number will be determined if field "l100" is a positive or a negative number.  If "l100" is a positive number then "l41" will be the sum of "l37"+"l38"+"l39"+"l100".  If "l100" is a negative number then "l41" will be the sum of "l37"+"l38"+"l39".

Here is the direction I thought might work.  Wondering if I'm on the right track or not:

var theField = this.getField("l100");

var theValue = theField.value;

var theField2 = this.getField("l37");

var theValue2 = theField2.value;

var theField3 = this.getField("l38");

var theValue3 = theField3.value;

var theField4 = this.getField("l39");

var theValue4 = theField4.value;

if (+theValue > 0) {

    this.getField("l41").value = +theValue + +theValue2 + +theValue3 + +theValue4;

}

else {

     this.getField("l41").value = +theValue2 + +theValue3 + +theValue4;  

}

I've tried to write this up and have had no success.  Any input would be much appreciated.

This topic has been closed for replies.
Correct answer George_Johnson

Here's what would be correct:

var theField = getField("l100");

var theValue = theField.value;

var theField2 = getField("l37");

var theValue2 = theField2.value;

var theField3 = getField("l38");

var theValue3 = theField3.value;

var theField4 = getField("l39");

var theValue4 = theField4.value;

if (+theValue > 0) {

    event.value = +theValue + +theValue2 + +theValue3 + +theValue4;

}

else {

     event.value = +theValue2 + +theValue3 + +theValue4; 

  }

1 reply

Inspiring
December 19, 2017

If that's a custom calculation script for l41, then wherever you have this:

this.getField("l41").value =

you should change it to this:

event.value =

Do this with any other calculation scripts that you may have set up similarly. Also, make sure that the field calculation order is set to whatever makes sense for your form. If you don't know what this is, post again and include which version of Acrobat you're using.

stepheng54012748
Known Participant
December 19, 2017

OK.  Here is what I came up with and it didn't work.  Right now I'm using Acrobat Pro 9.0.  I think the order is correct if I'm understanding you correctly.  The section of the form has 7 lines.

1.L34

2.L35

3.L36

3a.  L100

4.L37

5.L38

6.L39

7.L41

var theField = event.value ("l100");

var theValue = theField.value;

var theField2 = event.value ("l37");

var theValue2 = theField2.value;

var theField3 = event.value ("l38");

var theValue3 = theField3.value;

var theField4 = event.value ("l39");

var theValue4 = theField4.value;

if (+theValue > 0) {

    event.value ("l41").value = +theValue + +theValue2 + +theValue3 + +theValue4;

}

else {

     event.value ("l41").value = +theValue2 + +theValue3 + +theValue4;  

  }

stepheng54012748
Known Participant
December 19, 2017

Here's what would be correct:

var theField = getField("l100");

var theValue = theField.value;

var theField2 = getField("l37");

var theValue2 = theField2.value;

var theField3 = getField("l38");

var theValue3 = theField3.value;

var theField4 = getField("l39");

var theValue4 = theField4.value;

if (+theValue > 0) {

    event.value = +theValue + +theValue2 + +theValue3 + +theValue4;

}

else {

     event.value = +theValue2 + +theValue3 + +theValue4; 

  }


Once again, Thank you!  I'm going to study how you fixed this up.  This is much more difficult than I thought.  I think once i get the hang of the scenarios it will boil down to knowing how to find things like "event" etc.  Thank you again!  Hope you have a great holiday!