• Resolved borgesleti

    (@borgesleti)


    Hello, I need help with the dropdown fields.
    i’m trying to make a conditional function when an option from my list is checked. I’m calculating a weighted average.

    I would like to know if it is possible to set weights for each dropdwon field of my form and add these values, and if it is also possible to put an option in the dropdwon of not adding the weight of this field to the calculation.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter borgesleti

    (@borgesleti)

    Plugin Author codepeople

    (@codepeople)

    Hello @borgesleti

    Thank you very much for using our plugin.

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

    Assuming you have three dropdown fields fieldname1, fieldname2, and fieldname3.

    Please, enter numbers only as the choices values, and the text you prefer as their texts. For the “no adding weight” options, enter the number zero as their values.

    Now, you can insert a calculated field in the form and enter the following equation:

    (function(){
        var weights = [fieldname1, fieldname2, fieldname3], 
            n = 0, 
            total=0;
    
        for(var i in weights)
        {
            if(weights[i]){n++;total+=weights[i];}
        }
    
        return total/n;
    })()

    Best regards.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘conditional logic with dropdown’ is closed to new replies.