Skip to main content
Participating Frequently
December 12, 2008
Question

FORM CALCULATIONS: multiplying 2 fields with a fixed number

  • December 12, 2008
  • 14 replies
  • 23741 views
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
    This topic has been closed for replies.

    14 replies

    Inspiring
    February 2, 2009
    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
    Known Participant
    April 21, 2024

    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.

     

    Nesa Nurani
    Community Expert
    Community Expert
    April 21, 2024

    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.

    Inspiring
    February 2, 2009
    Rafael,

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

    George
    Participant
    January 31, 2009
    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!
    Participating Frequently
    December 16, 2008
    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
    Inspiring
    December 15, 2008
    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
    Participating Frequently
    December 15, 2008
    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
    Participating Frequently
    December 15, 2008
    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
    Inspiring
    December 15, 2008
    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
    Participating Frequently
    December 15, 2008
    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
    Inspiring
    December 15, 2008
    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