Help with JavaScript Formula off a dropdown menu

Community Beginner ,
May 21, 2019

Copy link to clipboard

Copied

Hi I need help with a formula based on a dropdown menu entry:

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

Java Script 5 Meals.jpg

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

272

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

Help with JavaScript Formula off a dropdown menu

Community Beginner ,
May 21, 2019

Copy link to clipboard

Copied

Hi I need help with a formula based on a dropdown menu entry:

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

Java Script 5 Meals.jpg

TOPICS
Acrobat SDK and JavaScript, Macintosh

Views

273

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
May 21, 2019 0
Adobe Community Professional ,
May 21, 2019

Copy link to clipboard

Copied

If I were doing this I'd use a custom Validate script for the dropdown. But I'd need to know what the possible selections are. You've mentioned dropdown selections of 5, 4, and 3, but are there any others? In particular, it there one that indicates no valid selection (e.g., "--" or " ")?

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...
May 21, 2019 1
Community Beginner ,
May 21, 2019

Copy link to clipboard

Copied

Hi George,

the dropdown menu is number of meals - and the values are 3 meals, 4 meals or 5 meals only so the form suggests 3 meals as a minimum. So there aren't any others.

literally just three option in the drop down 3,4, or 5. Theres no options for no selection.

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...
May 21, 2019 0
Adobe Community Professional ,
May 21, 2019

Copy link to clipboard

Copied

OK, with that and further review of the form, it would probably be best to use custom validation script for the Grams fields. But before I suggest a script, are you calculating the Grams given the Calories, or vice versa, or are they both manually entered, or something else?

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...
May 21, 2019 0
Community Beginner ,
May 21, 2019

Copy link to clipboard

Copied

Hi George,

thanks for your reply, i'm looking for dividing the grams.

The form works as follows:

1. Enter weight (lbs) into Weight box / field.

2. Weight in lbs x 10 to give us the calorie amount in the calorie box field

3. Protein calories box's calculated by calories x 0.40 = Protein calories, Protein calories then divided by 4 to give us GramsProtein

4. Carb calories box's calculated by calories x 0.25 = Carbohydrates Calories, CarbCalories then divided by 4 to gives us GramsCarbs

5. Fat Calories Box calculated by calories x 0.35 = FatsCalories, then divided by 9 to gives us GramsFats.

Now this is where I need the help - the grams of the food is then divided by the dropdown menu "No.ofMeals" either 3,4 or 5 selected.

I have 5 box's / fields = Meal 1, Meal 2, Meal 3, Meal 4, Meal 5.

The protein calculation was easier as it was "GramsProtein" / 5 - an equal amount of protein across each meal.

However I want the "GramsCarbs" to divide by 2 and

If 5 Meals selected from "No.ofMeals" box then the values to show in Meal 5 and Meal 4 only.

If 4 Meals Selected from "No.ofMeals" box then values to show in Meals 4 and Meal 3 only.

If 3 Meals selected from "No.ofMeals" box the values to show in Meals 3 and 2 only.

So the carbohydrates in grams are divided by two to be had at the last two meals of the day depending on "No.ofMeals" selected.

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
Reply
Loading...
May 21, 2019 0