Skip to main content
Participating Frequently
December 12, 2008
Question

FORM CALCULATIONS: multiplying 2 fields with a fixed number

  • December 12, 2008
  • 14 replies
  • 23745 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

    Participating Frequently
    December 14, 2008
    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
    Inspiring
    December 14, 2008
    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
    Participating Frequently
    December 13, 2008
    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
    Inspiring
    December 12, 2008
    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