• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Participant ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

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.

TOPICS
Acrobat SDK and JavaScript , Windows

Views

378

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Dec 18, 2017 Dec 18, 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; 

  }

Votes

Translate

Translate
LEGEND ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

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;  

  }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

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; 

  }

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Dec 18, 2017 Dec 18, 2017

Copy link to clipboard

Copied

LATEST

In a calculation script, you set the value of the field that it's attached to by assigning the calculated value to event.value

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines