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

calculate result triggered by selected fields

Community Beginner ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

Hi, I need to calculate a result in PDF form. I have 5 fields: kg, lbs, result, quantity and ml.

 

The formula for result is event.value = Number(this.getField("kg").valueAsString) * 1.8;

> for this formula the user could enter a value in either "kg" or "lbs"

If the user enters the value in "kg", I want the "lbs" to automatically populate and vice versa.  

calculation is "lbs = kg * 2.2" or "kg = lbs / 2.2"

 

The formula for quantity is event.value = Number(this.getField("result").valueAsString) / 50;

The formula for ml is event.value = Number(this.getField("result").valueAsString) / 5;

 

How can I make this ?

 

 

 

TOPICS
PDF forms

Views

568

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 ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

What should happen if they fill in both the "kg" and the "lbs" fields?

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 Beginner ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

@try67 

 

if I enter 50kg the lbs field should show 88.

If I change 88 to 110 in lbs the kg field should update to 50, etc. (based on the calculation)

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 ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

As the custom Validation script of "kg" enter this:

 

this.getField("lbs").value = (event.value) ? event.value * 2.20462 : "";

 

And as the custom Validation script of "lbs" enter this:

 

this.getField("kg").value = (event.value) ? event.value *  0.453592 : "";

 

[Edited: values were reversed. Thanks, @Nesa Nurani ]

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 Beginner ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

@try67 Ok for these that works, but what would be the script for the "result' field to pick either "kg" or "lbs" ?

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 ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

It doesn't matter, since the values will both be the same. Just choose one and use it.

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 ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

2.20462 should go in "kg" and 0.453592 should go in "lbs".

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 ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

Sorry, yes, will fix now...

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 Beginner ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

last thing. I need to limit the "result" to be no higher than 180

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 ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

LATEST

Add this to the end of your calculation script:

 

event.value = Math.min(180, 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 Beginner ,
Apr 08, 2022 Apr 08, 2022

Copy link to clipboard

Copied

Last thing. I need to limit the "result" to be no higher than 180

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