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

FORM CALCULATIONS: multiplying 2 fields with a fixed number

New Here ,
Dec 12, 2008 Dec 12, 2008

Copy link to clipboard

Copied

i have 2 text fields that i'm multiplying using Text field properties/CALCULATE. It works, but now i need to multiply that sum by a fixed number of 2. How can i take the sum of those 2 fields and multiply it by a fixed number of 2?

Thanks for any insight.
Mary

Views

22.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
LEGEND ,
Dec 12, 2008 Dec 12, 2008

Copy link to clipboard

Copied

At first you say you're multiplying the two fields and then say you want to add them. Assuming you want to add them, a custom calculation script for the calculated field could look like:


// Get first field value, as a number
var v1 = +getField("Text1").value;

// Get second field value, as a number
var v2 = +getField("Text2").value;

// Calculate and set this field's value to the result
event.value = 2 * (v1 + v2);


Be sure to set any calculated fields to read-only so the user can't attempt to interact this them.

George

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 ,
Dec 13, 2008 Dec 13, 2008

Copy link to clipboard

Copied

THANK YOU! I was able to make that work. Now, almost there, i have a glitch that i'm unable to solve. The last three calculated fields in my form cause an error to be displayed, but it works ok. The error is: ( The value entered does not match the format of the field [text1] )

I don't want to be bothered with having to enter thru this pesky message 3 times so i'm trying to resolve it.

Each of the three fields calculate from other input on the form. The only way i don't get the pesky error that pops up, is to set the Format Catetory for each of this fields to NONE. But then the number is NaN or infinity until the form is filled out, and the result is a really long number. I have tried to change this to simply, Number, with 2 decimals.

Any insight to this? i've tried every way i can think of....

thanks
mary

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 ,
Dec 13, 2008 Dec 13, 2008

Copy link to clipboard

Copied

Are you doing divisions? In any case, post the code you're using for the calculaton so we can tell what's going on.

George

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 ,
Dec 14, 2008 Dec 14, 2008

Copy link to clipboard

Copied

Yes, it is dividion. I'm not using anything too sophisticated.

Field A is data input. (ypp)

Field B is the sum calculated by other fields. (totalwarpyards)

Field C is the sum calculated by other fields. (totalweftyard)

Field D is the sum addition of B & C. ( totalwarpyards, totalweftyards )

Field E is the calculated sum amount of Field D, then divided by A. (warpweftyardage/ypp)

seems pretty straight forward, but if i change the Format to be anything but NONE, i get that pesky error message (although it works properly. weird huh?)

thanks so much for giving me so much help!
mary

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 ,
Dec 14, 2008 Dec 14, 2008

Copy link to clipboard

Copied

No, that's very common when doing division. The problem happens when the divisor is zero (or otherwise evaluates to zero). This will happen when the field A is blank. When you divide by zero with JavaScript, the result is equal to one of three special numeric values: Infinity, -Infinity, or NaN (Not a Number, 0/0). The fix is to check for a divisor of zero, and perform the calculation if it is not zero. If it is zero, you have to decide what the calculated field value should be. A common thing to do is set the value to nothing (blank). If you need help with the script, please post the exact script that you're currently using.

George

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 ,
Dec 15, 2008 Dec 15, 2008

Copy link to clipboard

Copied

Hi George, Can i give you link to the pdf online? http://www.villageweaver.com/warp_calc_worksheet.pdf
the last 3 fields (all under the Letter Z are my problem children)

thanks.
mary

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 ,
Dec 15, 2008 Dec 15, 2008

Copy link to clipboard

Copied

Mary,

Below is a script you can use as the custom calculation script for the "lbsandounces" field:


(function () {

// Get the field values, as numbers
var wwy = +getField("warpweftyardage").value;
var ypp = +getField("ypp").value;

// Perform calculation and set this field value to result
if (ypp !== 0) {
event.value = wwy / ypp;
} else {
// If ypp = 0, blank this field
event.value = "";
}

})();


You'd do something similar for the other two fields, but specify the correct field names.

George

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 ,
Dec 15, 2008 Dec 15, 2008

Copy link to clipboard

Copied

George,
Thank you so much for taking the time to help me. The code you so generously gave me worked perfectlly. Thanks so much for the help - my little form works brilliantly for my needs! finally and without all those pesky little errors!

Thanks again.
Mary

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 ,
Dec 15, 2008 Dec 15, 2008

Copy link to clipboard

Copied

Hey George, Can I pick your brain again. in the same doc (still online - newly modified with your groovy code) i have a little teaser. Letter N is an important number for me, and i find that if i should change B, E, J, or L, the results of N seem to go all over the board. I can change the number of E four times, and N will give me 4 different results.... Any ideas?

Thanks very much -
Mary

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 ,
Dec 15, 2008 Dec 15, 2008

Copy link to clipboard

Copied

I'm not sure I understand your question, but if you're getting incorrect results I believe your field calculation order is incorrect. So to fix it you should set the field calculation order to whatever makes sense for your form.

I also noticed that the calculation for the (C) field is causing an error. If you change it to be the Sum of "how_wide_is_the_project_in_nches", it should be OK.

Also, is it "fringe" or "finge", or both? I see both spellings.

George

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 ,
Dec 15, 2008 Dec 15, 2008

Copy link to clipboard

Copied

Thanks George! The field calculation was it. I hope the (C) field is fixed. It didn't give me an error, so i'm hoping that i fixed it ok, based on the directive you gave me.

Thanks again for all your help.
Mary

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 ,
Jan 31, 2009 Jan 31, 2009

Copy link to clipboard

Copied

I'm new here and don't have much experience.

I am using Acrobat 9 Pro Extended. I am working on a form that allows you to enter Income amounts for Hospital Charity Care program.

What I want to do is the following:
#1 Add these 9 fields together- (Welfare,Soc Sec,VA Pension,Text15,Text16,Text17,Text18,Text19,Last 1 month) and then multiply by 12

#2 There is a field named "Last 3 Months" I want to multiply that by 4(the catch is I don't want the total displayed on the field)

#3 I want to add The total of #1, #2 and a field named "Annualized"

The total of all of this would go onto a field names "Last 12 Months"

I want to write the script to do all these calculations on the "Last 12 Month" field

I've tried different methods but it doesn't seem to calculate automatically as I change the numbers.

Please help!

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 ,
Feb 01, 2009 Feb 01, 2009

Copy link to clipboard

Copied

Rafael,

If you send me an email and include your form, I'll see what I can do.

George

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 ,
Feb 02, 2009 Feb 02, 2009

Copy link to clipboard

Copied

See if this is what you want:


(function () {

// Get alll of the field values, as numbers
var v1 = +getField("Welfare").value;
var v2 = +getField("Soc Sec").value;
var v3 = +getField("VA Pension").value;
var v4 = +getField("Text15").value;
var v5 = +getField("Text16").value;
var v6 = +getField("Text17").value;
var v7 = +getField("Text18").value;
var v8 = +getField("Text19").value;
var v9 = +getField("Last3Months").value;
var v10 = +getField("Annualized").value;

// Calculate the result and set this field value
event.value = 12 * (v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8) + (4 * v9) + v10;

})();


George

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
Explorer ,
Apr 20, 2024 Apr 20, 2024

Copy link to clipboard

Copied

None of this makes sense to me. I figured if I double clicked the field where I want the product to go and specified which forms to multiply it would calculate. I can't be putting in all those formulas.

 

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 20, 2024 Apr 20, 2024

Copy link to clipboard

Copied

LATEST

Can you explain exactly what you need?

If you have simple calculations, you can go to 'Calculate' tab of 'Total' field select 'Value is the' then select 'product(x)' (for multiply) and then 'Pick' to select which fields you wish to multiply, for little more advanced calculations you can use 'Simplified field notation' (also under 'Calculate' tab) where you enter formulas using field names, for example: field1*field2 or field1*field2+field3...etc (it's best to use field names without spaces in their names).

For more advanced calculations, you would need custom calculation script.

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