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

Calculation script to increment after specific variable entered

New Here ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

Hello!

 

I am working on a PDF form and need help with a calculation script. A user must enter a variable integer in Line A. Based off that input a value populates in another field, Line B. If the variable >=6, then it increments by a set value (See table below, note: 1-6 do not increment based off the value after 6).

 

Talia5EC7_0-1714607625211.png

So far, I have created this but am certain it's not correct and lost for the incrementing part:
 
var a = this.getField("line_A").value; //variable for Line A
if (a == "1") event.value = 2000;
else if (a == "2") event.value = 2848;
else if (a == "3") event.value = 3694;
else if (a == "4") event.value = 4540;
else if (a == "5") event.value = 5390;
else if (a == "6") event.value = 6234;
else if (a >= "7") event.value = 7570;
else {
event.value = "";}

Any help is greatly appreciated!!!

TOPICS
Create PDFs , JavaScript , Modern Acrobat , PDF , PDF forms

Views

158

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

Community Expert , May 01, 2024 May 01, 2024

If you add 848 to any value after 6 why did you add 7570, shouldn't it be 7082 for 7, and 7930 for 8...etc?

Here is the script that will add 848 to values after 6:

var a = Number(this.getField("line_A").valueAsString);
var values = [2000, 2848, 3694, 4540, 5390, 6234];
var increment = 848;

if (a > 0) {
 if (a <= 6) {
  event.value = values[a - 1];} 
 else {
  event.value = values[5] + increment * (a - 6);}} 
else {
 event.value = "";}

Votes

Translate

Translate
Community Expert ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

Hi @Talia5EC7 ,

 

You may try something like this as the custom calculation script of line_B field:

 

var a = this.getField("line_A").value;

if (a !== "") {

if (a == 0)  {event.value = 0}
if (a == 1)  {event.value = 2000}
if (a == 2)  {event.value = 2848}
if (a == 3)  {event.value = 3694}
if (a == 4)  {event.value = 4540}
if (a == 5)  {event.value = 5390}
if (a == 6)  {event.value = 6234}
if (a >= 7)  {event.value = 7570}

} else {

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
Community Expert ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

If you add 848 to any value after 6 why did you add 7570, shouldn't it be 7082 for 7, and 7930 for 8...etc?

Here is the script that will add 848 to values after 6:

var a = Number(this.getField("line_A").valueAsString);
var values = [2000, 2848, 3694, 4540, 5390, 6234];
var increment = 848;

if (a > 0) {
 if (a <= 6) {
  event.value = values[a - 1];} 
 else {
  event.value = values[5] + increment * (a - 6);}} 
else {
 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
Community Expert ,
May 01, 2024 May 01, 2024

Copy link to clipboard

Copied

Beautiful script @Nesa Nurani , thank you as usual  for catching these details.

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
New Here ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

LATEST

Hi @Nesa Nurani,

 

I totally forgot to leave that off, it was just a placeholder. Thank you so much, this worked perfect!! Are you able to provide any resources or refer me to any books that cover these types of calculations. I've googled so much but I am not sure what is legit. Thanks for your help and time, I really appreciate you!

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