• Resolved supersvetodiod

    (@supersvetodiod)


    Good afternoon! There are physical formulas: s=v*t; v=S\t; t=S\v. I need these calculations to be performed using a drop-down list. The list is set up. field 2 – v; field 3 – t; field 4-S. The following formula was entered in the calculation: fieldname4/(fieldname2, fieldname3). The calculation is performed only if there is data in field 2. If there is a field 3 and we fill it in, then the calculation does not go. According to the formula: fieldname4/(fieldname2, fieldname3) we can only calculate v=S\t; t=S\v. How to make sure that s=v*t is also calculated

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

    (@codepeople)

    Hello @supersvetodiod

    You cannot merge the equations in that way. In mathematic, this operation has no sense A=B/(C,D) in the programming happens the same.

    If you want to calculate S, the equation would be: fieldname2*fieldname3

    To calculate V, the equation would be: fieldname1/fieldname3

    And to calculate t: fieldname1/fieldname2

    Best regards.

    Thread Starter supersvetodiod

    (@supersvetodiod)

    In one form, you will not be able to combine three calculators, which, depending on which variable you need to find, will give the answer. Example:https://allcalc.ru/node/758

    Plugin Author codepeople

    (@codepeople)

    Hello @supersvetodiod

    Why not? You can use conditional statements in the equation to calculate a value or another depending on the radio button selected, like in the form you sent me as a reference.

    Best regards.

    Thread Starter supersvetodiod

    (@supersvetodiod)

    is there an example of how to implement this? On the forum or in the documentation?

    Plugin Author codepeople

    (@codepeople)

    Hello,

    For example, Assuming you have a radio button with three choices: A, B, and C (the fieldname4), and three calculated fields: fieldname1, fieldname2, and fieldname3.

    And you want to implement the following equations:

    In the fieldname1 field, if the choice “A” is selected, you want to calculate fieldname2*fieldname3. If any other choice in fieldname4 is ticked, return the value entered by the user.

    In the fieldname2 field, if the choice “B” is selected, you want to calculate fieldname1/fieldname3 or the value entered by the user.

    In the fieldname3 field, if the choice “C” is selected, you want to calculate fieldname1/fieldname2 or the value entered by the user.

    The equations described above can be implemented as follows:

    The equation of the fieldname1 field:

    IF(fieldname4=='A', fieldname2*fieldname3, __ME__)

    The equation of the fieldname2 field:

    IF(fieldname4=='B', fieldname1/fieldname3, __ME__)

    The equation of the fieldname3 field:

    IF(fieldname4=='C', fieldname1/fieldname2, __ME__)

    Best regards.

    Thread Starter supersvetodiod

    (@supersvetodiod)

    in my example: there are three options in the drop-down list - "Speed", "Time" and "Distance". They are so called in the drop-down list, but on russian. Next, you need to write the following code in the set equation field:
    
    (function(){
    IF (fieldname1=='Скорость', fieldname3*fieldname4, __ME__)
    IF(fieldname1== 'время', fieldname3*fieldname4, __ME__)
    IF (fieldname1=='расстояние', fieldname2/fieldname3, __ME__)
    })()
    Thread Starter supersvetodiod

    (@supersvetodiod)

    __ME__ – what is that

    Plugin Author codepeople

    (@codepeople)

    Hello @supersvetodiod

    In the equations __ME__ returns the current value of the calculated field.

    Your equation’s code is incorrect. In my previous entry, I’ve described how to implement the process with three calculated fields configured as editable and a radio button or dropdown field to decide which of them to calculate.

    However, if you want to implement the process with three number fields and only want calculated field, the equation would be:

    (function(){
    if(fieldname1=='Скорость') return fieldname3*fieldname4;
    if(fieldname1== 'время') return fieldname3*fieldname4;
    if(fieldname1=='расстояние') return fieldname2/fieldname3;
    })()

    Javascript is a case-sensitive language. Please, do not confuse the “if” conditional statement of javascript with the “IF” operation in the plugin. Furthermore, if you implement the equation with function structure, you must use “return” instructions to return the result to the calculated field.

    The previous equation can be implemented by using the “IF” operation, and without function structure as follows:

    IF(fieldname1=='Скорость', fieldname3*fieldname4, IF(fieldname1=='время', fieldname3*fieldname4, fieldname2/fieldname3))

    Best regards.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘calculating drop-down lists’ is closed to new replies.