• Resolved Tooni

    (@tooni)


    Somewhere in documentation or FAQ there is an example for using a function for a field calculation.
    I would like to use the same function for several fields. I think the function would need a name and one (or more) input paramerters. I can imagine how to do this, but I don’t know, where to place the definition of the function without execution.
    Can you explain how to achieve this?

    Regards, Tooni

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @tooni

    I’ll try to describe the process with a hypothetical example.

    Assuming you want to implement a function that calculates the hypotenuse of a right triangle given two sides. Furthermore, you want to call this function from the calculated fields.

    1. Insert an “HTML Content” field in the form with a piece of code similar to the following one, as its content, to define the new function:

    
    <script>
    function hypotenuse(a,b)
    {
    return SQRT(POW(a,2)+POW(b,2));
    }
    </script>
    

    2. Now, if there are two number fields in the form for entering the triangle’s sides (fieldname1 and fieldname2), and you want to calculate the hypothenuse. Insert a calculated field in the form and enter the following equation through its “Set equation” attribute:

    
    hypothenuse(fieldname1, fieldname2)
    

    Note: you can call this function with all calculated fields in the form.

    Best regards.

    Thread Starter Tooni

    (@tooni)

    That works without any problems. Thank you very much!

    Regards, Tooni

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to use functions in calculation?’ is closed to new replies.