Two values for the same option in checkboxes

[ad_1]

Hello @tomchase

The quick answer to your question is “Not by default”. However, there are some alternatives.

  • You can create a plain object with the values and use the checkbox choices as object indexes.

Assuming you have the checkbox field fieldname1 and configured it as follows: Entered the 1, 2, and 3 numbers as the choices’ values, and unticked the “Merge ticked up options (sum or concatenation) or their values are returned as an array” checkbox in the field’s settings.

You can insert a calculated field in the form and enter the equation:


(function(){
    var result = 0,
        obj = {1:[3,7], 2:[10,18], 3:[1,45]},
        index;

    for(let i in fieldname1){
      index = fieldname1[i];
      result = SUM(result, obj[index][0]*obj[index][1]);
    }
    return result;
})()

The previous equation gets the values of ticked choices and uses them as indexes for the obj property. Finally, it sums the multiplication of the associated numbers.

  • Second alternative, you can format the choices’ values as follows:

Enter 3|7 as the first choice’s value.
Enter 10|18 as the second choice’s value.
And finally, enter 1|45 as the third choice’s value.

Now, you can implement the equation as follows:

(function(){
    var result = 0,
        values;

    for(let i in fieldname1){
      values = fieldname1[i].split('|');
      result = SUM(result, values[0]*values[1]);
    }
    return result;
})()

Best regards.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer