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

Adobe Fillable form drop down menu formula help

Community Beginner ,
May 21, 2019 May 21, 2019

Copy link to clipboard

Copied

Hi,

I am having problem with creating a fillable form formula to work in adobe. I have created a drop down menu titled "No.ofMeals", values being 3,4 and 5. I want the form to divide the field "ProteinGrams" by whats selected from the drop down - so divided by either 3,4,5. Thanks

TOPICS
Acrobat SDK and JavaScript

Views

182

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
community guidelines

correct answers 1 Correct answer

Community Expert , May 21, 2019 May 21, 2019

As the custom calculation script of the field where you want to show the result, enter this:

event.value = Number(this.getField("ProteinGrams").valueAsString) / Number(this.getField("No.ofMeals").valueAsString);

Likes

Translate

Translate
Community Expert ,
May 21, 2019 May 21, 2019

Copy link to clipboard

Copied

As the custom calculation script of the field where you want to show the result, enter this:

event.value = Number(this.getField("ProteinGrams").valueAsString) / Number(this.getField("No.ofMeals").valueAsString);

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
community guidelines
Community Beginner ,
May 21, 2019 May 21, 2019

Copy link to clipboard

Copied

Hi try67,

thanks for your response. the formula you provided works but is not quite 100% right yet.

to give you a scenario I have created a PDF Nutrition form that when you enter your weight (lbs) into the "Weight" field it will calculate a Total Calories sum in the "Total Calories" Field (Formula is weight in lbs x 10 kcal).

Now we have the total Calories field filled in based on selection of weight e.g. 150 lbs x 10 = 1500 calories.

The form then calculates %'s of food into the following fields -

"Calories Protein" =  (1500 x 0.40) this then gives the "GramsProtein" (CaloriesProtein/4)

"Calories Carbohydrates" = (1500 x 025) this then gives us "GramsCarbs" (CaloriesCarbs/4)

"CaloriesFats" = (1500 x 0.35) this then gives us "GramsFats" (CaloriesFats/9)

The percentages of food from the total calories calculated are 40% Protein, 25% Carbs, 35% Fats.

I have managed to sort all this bit of the form perfectly myself.

The bit I am now struggling with is to divide the grams of food based on the dropdown menu "No.ofMeals" selection. - 3,4, or 5.

There are 5 individual meals boxes:

Meal 1

Meal 2

Meal 3

Meal 4

Meal 5

your suggestion divides all equally so the form does this:

So if 150 lbs x 10 kcal = 1500 kcal

Protein 150 grams

Carbs 93.75

Fats 58g.

Your calculation "works" except if I was to chose 3 meals 50 grams of protein shows in every box:

Meal 1: 50

Meal 2: 50

Meal 3: 50

Meal 4: 50

Meal 5: 50

If I now select 3 meals on the drop down menu 50grams shows in all 5 meal boxes rather than just 3.

the total grams of protein shows now 250g grams which doesn't make sense / wrong calculation as the total grams of protein is only 150.

I need the form to calculate the meals based on selection of "No.ofMeals" from the drop down menu.

So if 3 meals selected the form only divides Protein by 3 to show protein in meals 1, 2 and 3 boxes.

If the user selects 4 meals I need the form to divide  protein by 4 to show protein grams in meals 1,2,3 and 4. only

and obviously is user selects 5 meals the form shows "ProteinGrams" / 5 to show calculation in all 5 boxes.

Hope all makes sense. Attached a photos to help.JavaScript Formula 2.jpgJava Script Formula1.jpg

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
community guidelines
Community Expert ,
May 21, 2019 May 21, 2019

Copy link to clipboard

Copied

OK, that's not quite what you asked for before...

There are various ways of doing it. Maybe the easiest is to add a condition to the 4th and 5th fields to only show the result if 4 or 5 are selected. Otherwise, keep them empty.

Something like this for field 4:

var numMeals = Number(this.getField("No.ofMeals").valueAsString);

if (numMeals==4 || numMeals==5) event.value = Number(this.getField("ProteinGrams").valueAsString) / numMeals;

else event.value = "";

And for field 5:

var numMeals = Number(this.getField("No.ofMeals").valueAsString);

if (numMeals==5) event.value = Number(this.getField("ProteinGrams").valueAsString) / numMeals;

else event.value = "";

The rest can remain the same.

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
community guidelines
Community Beginner ,
May 21, 2019 May 21, 2019

Copy link to clipboard

Copied

Hi try67,

Thanks for your help and input, really appreciated.

I've copied and pasted your formula but it now just has Meal 4 blank and meal 5 blank even if I select 4 meals or 5 meals in "No.ofMeals" both meal box 4 and meal box 5 are blank below.

Thanks

Java Script 4 Meals.jpg

Java Script 5 Meals.jpg

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
community guidelines
Community Expert ,
May 21, 2019 May 21, 2019

Copy link to clipboard

Copied

I need to see the actual file to be able to help you further. Can you share it, either via a file-sharing website (Dropbox, Google Drive, Adobe DC) or privately via email (try6767 at gmail.com)?

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
community guidelines
Community Beginner ,
May 21, 2019 May 21, 2019

Copy link to clipboard

Copied

Hi Try,

I need one more calculation then the form is complete. I am so thankful for your help...

Its the carbohydrates calculation.

If "No.ofMeals" selected is 5 I need the "GramsCarbohydrates" to divide by 2 and show in the last two boxes - meal 5 and meal 4 boxes.

If "No.ofMeals" selected is 4 I need the "GramsCarbohydrates" to divide by 2 and show in the boxes meals 4 and meals 3 and not to show at all in Meal 5 box.

If "No.ofMeals" selected is 3 I need the "GramsCarbohydrates" to divide by 2 and show in the boxes Meals 3 and Meals 2 and not to show in Meals 5 or 4 Boxes.

Hope that makes sense.

Thanks,

Chris

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
community guidelines
Community Beginner ,
May 21, 2019 May 21, 2019

Copy link to clipboard

Copied

LATEST

Hope you can help with the last formula Try - sure is very simple for you and wouldn't take you long.

Thanks so much.

Chris

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
community guidelines
Community Beginner ,
May 21, 2019 May 21, 2019

Copy link to clipboard

Copied

Hi Try 67,

found the problem my formula is GramsProtein not ProteinGrams - my bad this is excellent work thank you so much.

Chris

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
community guidelines