Calculated Field that return two values

[ad_1]

Hello @rui9075918

Thank you very much for using our plugin.

Your current equation fills the object properties “price” and “txt” and concatenates them before returning the equation’s result return info['price'] + info['txt'];

But now, you want to assign the price and txt to other two fields in the form. To describe the process, I’ll call them fieldname123 and fieldname321.

In this hypothetical case, you can edit the equation as follows:

(function () {
  var info = {};
  switch(fieldname21){
    case 1:
      info.price = 10;
      info.txt="A";
      break;
    case 2:
      info.price = 20;
      info.txt="B";
      break;
    case 3:
      info.price = 30;
      info.txt="C";
      break;
   
    default:
      info.price = 0;
      info.txt="no selection";
      break;
  }

  getField(fieldname123|n).setVal(info['price']);
  getField(fieldname321|n).setVal(info['txt']);
  return info['price'] + info['txt'];
})();

Note that I included two lines of code above the return instruction:

getField(fieldname123|n).setVal(info['price']);
 getField(fieldname321|n).setVal(info['txt']);

And pay special attention to the use of the |n modifier with the fields’ names fiedname123 and fieldname321. The plugin replaces the fields’ names with their values before evaluating the equations. The |n modifier tells the plugin you want to use the field’s name directly and not its value.

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