Highlighted

What Script Would You Use to populate numbers between a starting number and ending number?

New Here ,
Jul 18, 2020

Copy link to clipboard

Copied

I understand how to fill out the non calculated fields but I'm trying to figure out what script I would use say if someone were to type in just their start weight and their main goal.  I want the rest of the fields in between to populate with the appropriate numbers (Ie. 1, 2, 3, 4, Goal 1, 5, 6, 7, 8, Goal 2, 9, 10, 11, 12, Goal 3, 13, 14, 15, 16, Goal 4, 17, 18 & 19).  Is this doable and if so how would I go about doing it?

 

a5.jpg

TOPICS
How to

Views

29

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

What Script Would You Use to populate numbers between a starting number and ending number?

New Here ,
Jul 18, 2020

Copy link to clipboard

Copied

I understand how to fill out the non calculated fields but I'm trying to figure out what script I would use say if someone were to type in just their start weight and their main goal.  I want the rest of the fields in between to populate with the appropriate numbers (Ie. 1, 2, 3, 4, Goal 1, 5, 6, 7, 8, Goal 2, 9, 10, 11, 12, Goal 3, 13, 14, 15, 16, Goal 4, 17, 18 & 19).  Is this doable and if so how would I go about doing it?

 

a5.jpg

TOPICS
How to

Views

30

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
Jul 18, 2020 0
Adobe Community Professional ,
Jul 18, 2020

Copy link to clipboard

Copied

Yes, this is doable with Acrobat JavaScript. And there is a variety of ways that this can be done.

 

But in a nutshell, you basically declare variables and conditions to meet an expected result.

 

From looking at the screenshot you've provided,  I will use only one field of interest for my example.

 

Let's say the user enter data in the "Goal1" text field. And assuming you've already created the subsequent fields in that PDF, I will also assume that when the user enters any type of data in the "Goal1" field (which could also be a checkbox, depending on what exactly you're trying to do) it will automatically populate the subsequent four reward fields before the "Goal2" field.

 

So, in order  to develop your first  script it helps if you phrase your condition first in plain English like this:

 

If "Goal1" is empty nothing happens. But if Goal1 is not empty, then "Goal1_reward1" =1", "Goal1_reward2" =2", "Goal1_reward3" =3", "Goal1_reward4" =4".

 

 This is just a very quick basic concept of how to get yourself organized with the main idea(s) before you begin your script.

 

Once you have a plan, and all fields are created and named in whatever way you want them to be, then work your way up with your script to meet a result.

 

  • So step 1 - create your text fields and assign a field name for each
  • step 2 - use a custom calculation script that you may execute from the Goal1 text field; when the user types in any information in that field it will execute the script and display the results in the other fields that you want to populate with numbers. To do so, you will declare variables and also a series of conditions using conditional statements in that script
  • step 3 - test the script . If it works repeat the same for every Goal field. All you have to do is re-use this first script as a template with the other Goal text fields (all you have to do is change the field names in each script used for Goal2, Goal3, Goal4, respectively).

 

Below is how the script should  or would look like .

 

 

// as a basic rule of thumb always declare all of your variables first

var a = this.getField("Goal1_reward1").value;
var b = this.getField("Goal1_reward2").value;
var c = this.getField("Goal1_reward3").value;
var d =this.getField("Goal1_reward4").value;
 
// then set a condition and have the script execute an expected result based on those conditions

if (event.value !="")  {
this.getField("Goal1_reward1").value = "1";
this.getField("Goal1_reward2").value = "2";
this.getField("Goal1_reward3").value = "3";
this.getField("Goal1_reward4").value = "4";
}

else if (event.value =="") {
this.getField("Goal1_reward1").value = "";
this.getField("Goal1_reward2").value = "";
this.getField("Goal1_reward3").value = "";
this.getField("Goal1_reward4").value = "";
}

 

 

In my example code above I used the same names as I mentioned earlier ("Goal1_reward1", "Goal1_reward2", "Goal1_reward3", "Goal1_reward4") but you can change it in your form. Also, even though the variables that I declared are not needed for this script to work, I put them there on purpose so you can get a basic visual of the idea behind the basic scripting. 

 

It is convenient when you're resuing the code in other field and you have a long script. It is easier to express a =""; 

rather than  typing this.getField("Goal1_reward1").value = "";

 

This is true when using arithmetic operations (similar to basic algebra).

 

But anyway, you may copy the script above and paste it in your form field "Goal1" as shown in the slide below under "Calculate"  tab --->>> "Custome Calculation Script":

 

goal1.png

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...
Jul 18, 2020 0
ls_rbls LATEST
Adobe Community Professional ,
Jul 26, 2020

Copy link to clipboard

Copied

Hi,

 

Just following to see if you were able to sort this out.

 

Thank you.

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...
Jul 26, 2020 0