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

Help with a calculation - Using a number from a ratio

New Here ,
May 20, 2021 May 20, 2021

Copy link to clipboard

Copied

Hi everyone!

 

I am needing help with a calculation on one of the Acrobat forms I am working on. It is for an electrical company to use when removing and installing meters. Basically what I need help with is as below:

 

I have a calculation that needs to take a figure from a dropdown menu elsewhere in the form and use that in the calculation. I have the Javascript for the basis of the calculation already so I shouldn't need help with that. However, the info from the dropdown menu that I need is a ratio. For example 100/5. And the number that I need for the calculation is the '5' part of the ratio. How would I go about this in writing it in the custom calculation script?

 

Or would it be better if I just make the ratio into two dropdown boxes so that the calculation can take that second figure of the ratio directly from the separate dropdown menu?

 

Thanks in advance!

TOPICS
Edit and convert PDFs , How to , JavaScript , PDF forms

Views

1.1K

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 24, 2021 May 24, 2021

Don't call "num" as field it's variable , event.value = num*num*f2.value; should be enough.

Just watch for NaN, if you have blank as option in dropdown field use like this:

var drop = this.getField("ComboBox6").valueAsString;
var cComboBox6 = drop.split("/");
var num = cComboBox6[1];
var f2 = Number(this.getField("Calc3.0").value);
if(f2 == "" || drop == " ")
event.value = "";
else event.value = num*num*f2;

 

Votes

Translate

Translate
Community Expert ,
May 20, 2021 May 20, 2021

Copy link to clipboard

Copied

You can use 'split' to get number after '/'.

Lets say dropdown field is named "Ratio", you can use something like this:

var cRatio = this.getField("Ratio").valueAsString.split("/")
var num = cRatio[1];

 

In your example (100/5) variable 'num' will be 5 and you can use 'num' in your calculation.

Also in dropdown field properties under 'options' tab check 'Commit selected value immediately'.

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
New Here ,
May 23, 2021 May 23, 2021

Copy link to clipboard

Copied

Hi Nesa!

 

That first part worked perfectly thank you! Now I'm just trying to work it into my calculation. 

 

The calculation is for Calculated VA@full-load:  CT Secondary Current Max X Secondary Current Max X CT-Impedance Z. (Also known as: num X num X Calc3.0)

 

It is calculating the first part - num X num, however it's not calculating it by Calc3.0. It is missing this part of the equation. Any idea why? Have included a screenshot of my javascript here.

 

ComboBox6 is the dropdown field that I get the ratio from.

Screen Shot 2021-05-24 at 4.34.10 PM.png

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 ,
May 23, 2021 May 23, 2021

Copy link to clipboard

Copied

Check the Javascript console for errors.

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 ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

Don't call "num" as field it's variable , event.value = num*num*f2.value; should be enough.

Just watch for NaN, if you have blank as option in dropdown field use like this:

var drop = this.getField("ComboBox6").valueAsString;
var cComboBox6 = drop.split("/");
var num = cComboBox6[1];
var f2 = Number(this.getField("Calc3.0").value);
if(f2 == "" || drop == " ")
event.value = "";
else event.value = num*num*f2;

 

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
New Here ,
May 24, 2021 May 24, 2021

Copy link to clipboard

Copied

LATEST

Thank you Nesa! You're a life saver 🙂 It worked perfectly.

 

Have a great day!

 

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
LEGEND ,
May 20, 2021 May 20, 2021

Copy link to clipboard

Copied

You could also set the export value of each item in the dropdown to the corresponding number you want to use for each item.  If some item export values might be the same numerically, set the export values so they're unique as strings (e.g., "5", "5.0", "5.00", etc). You'd probably only do this sort of thing if you're not going to be extracting/exporting the form data in some manner.

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
New Here ,
May 23, 2021 May 23, 2021

Copy link to clipboard

Copied

Hi George,

 

Unfortunately the client will be exporting all the data from this PDF so that method may not work. Thank you for your input though!

 

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