Highlighted

java Script Formula to list different numbers depending on a number in another field

New Here ,
Sep 18, 2020

Copy link to clipboard

Copied

Hello There

I am having a hard time understanding the Java Script to create a formula (Never scripted before)

Let me try to explain what Im searching for since I couldnt find a solution by googling.

Field 1 is the field the calculation takes place

Field 2 is the field I want to be able to be edited and whos numbers Field 1 is refering to.

For Example:

 

If (Field 2) >= 100 that should give me a 1 in (Field 1)

If (Field 2) >= 300 that should give me a 2 in (Field 1)

If (Field 2) >= 800 that should give me a 3 in (Field 1)

 

I basically want to refer to a specific number in (Field 2) and get a defined number in (Field 1)

Like all numbers between 100 and 299 should say 1 in (Field 1)

and all numbers in between 300 and 799 should say 2 in (Field 1) and so on

 

Does a script like this exist or should I try a different method?

Thx for the help in advance

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use this script to achieve it:

 

var v = Number(this.getField("Field 2").valueAsString);

if (v>=800) event.value = 3;

else if (v>=300) event.value = 2;

else if (v>=100) event.value = 1;

else event.value = "";

TOPICS
Acrobat SDK and JavaScript, Create PDFs, How to

Views

68

Likes

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

java Script Formula to list different numbers depending on a number in another field

New Here ,
Sep 18, 2020

Copy link to clipboard

Copied

Hello There

I am having a hard time understanding the Java Script to create a formula (Never scripted before)

Let me try to explain what Im searching for since I couldnt find a solution by googling.

Field 1 is the field the calculation takes place

Field 2 is the field I want to be able to be edited and whos numbers Field 1 is refering to.

For Example:

 

If (Field 2) >= 100 that should give me a 1 in (Field 1)

If (Field 2) >= 300 that should give me a 2 in (Field 1)

If (Field 2) >= 800 that should give me a 3 in (Field 1)

 

I basically want to refer to a specific number in (Field 2) and get a defined number in (Field 1)

Like all numbers between 100 and 299 should say 1 in (Field 1)

and all numbers in between 300 and 799 should say 2 in (Field 1) and so on

 

Does a script like this exist or should I try a different method?

Thx for the help in advance

Most Valuable Participant
Correct answer by try67 | Most Valuable Participant

You can use this script to achieve it:

 

var v = Number(this.getField("Field 2").valueAsString);

if (v>=800) event.value = 3;

else if (v>=300) event.value = 2;

else if (v>=100) event.value = 1;

else event.value = "";

TOPICS
Acrobat SDK and JavaScript, Create PDFs, How to

Views

69

Likes

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
Sep 18, 2020 0
Most Valuable Participant ,
Sep 18, 2020

Copy link to clipboard

Copied

You can use this script to achieve it:

 

var v = Number(this.getField("Field 2").valueAsString);

if (v>=800) event.value = 3;

else if (v>=300) event.value = 2;

else if (v>=100) event.value = 1;

else event.value = "";

Likes

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
Reply
Loading...
Sep 18, 2020 0
New Here ,
Sep 18, 2020

Copy link to clipboard

Copied

Hmm. So I applied it and made this:

 

var v = Number(this.getField("XP1").valueAsString);
if (v>=355000) event.value = 20;
else if (v>=305000) event.value = 19;
else if (v>=265000) event.value = 18;
else if (v>=225000) event.value = 17;
else if (v>=195000) event.value = 16;
else if (v>=165000) event.value = 15;
else if (v>=140000) event.value = 14;
else if (v>=120000) event.value = 13;
else if (v>=100000) event.value = 12;
else if (v>=85000) event.value = 11;
else if (v>=64000) event.value = 10;
else if (v>=48000) event.value = 9;
else if (v>=34000) event.value = 8;
else if (v>=23000) event.value = 7;
else if (v>=14000) event.value = 6;
else if (v>=6500) event.value = 5;
else if (v>=2700) event.value = 4;
else if (v>=900) event.value = 3;
else if (v>=300) event.value = 2;
else event.value = 1;

 

But it doesnt seem to work. It always just shows a 1. Did I do anything wrong?

Likes

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
Reply
Loading...
Sep 18, 2020 0
New Here ,
Sep 18, 2020

Copy link to clipboard

Copied

Ok Nevermind I am stupid. It just didnt update when I looked at the draft preview. I closed the tool and now it works! Thank you very much 😄

Likes

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
Reply
Loading...
Sep 18, 2020 0