Hi,
My recommendation is to use the prices directly as the checkboxes values, for example the value of the option A would be 100, the value of the option B would be 200, and so on, and finally, if the field of the checkboxes is the fieldname3, and your current equation is fieldname1+fieldname2 (the name of fields and the equation is only to demonstrate the point), the equation only should be edited as follows:
fieldname1+fieldname2+fieldname3
you only should sum the new field, to the rest of the equation.
and that’s all.
Best regards.
Hi,
Thank you very much for the prompt reply. I was really impressed.
However, in my first question, I made a little simplification of the real issue in order to get the main idea from you. I am running a translation service site and the problem is a little bit more complicated. Here it is.
I have three input fields:
+ fieldname24: source language, this is a dropdown and customer will choose the source language of the document that needs to be translated.
+ fieldname25: target language, this is a checkbox comprising a list of target languages that customer can choose. Obviously they can choose more than 1 target language.
+ fieldname26: number of words need to be translated, which customer will input into.
For each combination of source language and target language, there is a specific price per word. And then the price per word * number of words will return the translation fee.
I compose the formular, the excerp of which is as below (the full language list is quite long and so is the formular), and I am good to go in case ONLY ONE option selected in the target language field. If more than one option is selected, however, I don’t know which function or fuction combination can address this.
if(fieldname24==1&&fieldname25==2){ return (fieldname26*0.08);}if(fieldname24==3&&fieldname25==2){ return (fieldname26*0.12);}
Note: I’m testing with the free version to make sure it can meet my calculation requirement before I go ahead buying the pro-version.
Thank a lot!
Hi,
The solution you propose is fine:
(function(){
if(fieldname24==1&&fieldname25==2) return (fieldname26*0.08);
if(fieldname24==3&&fieldname25==2) return (fieldname26*0.12);
…..
})()
But you can implement the equation a little different to optimize the process, in the previous equation should be replaced each string with the format fieldnameX with its value, and then evaluate the equation, with many languages, the possible combinations, and the number of replacements may be huge.
if you create a bidimensional matrix in the equation with the price of pair of languages, will be needed only three replacements:
(function(){
var prices = [[0,0.08,0.12],[0.03,0,0.05]];
return price[fieldname24][fieldname25]*fieldname26;
})()
You should create the complete matrix with all combinations.
Best regards.
Hi,
Thanks for your advice. It works perfectly in case only one language is selected in the target language checkbox. However, if more than one target language is selected, it cannot sum up the results from each language pair. Do you have any idea about that?
Thank you very much!
Hi,
The equation you need is a little more complex, because you are allowing select only one language as source (because the original text is in only one language. Use in this case a dropdown control, or radio buttons), and many languages for translation (using checkboxes for translations). So, the fieldname25 will return the sum of selected languages and not the choices by separated. My recommendation is modify your form like follow:
First, assign a class name to the list languages for translations, for example myclass (the class names are assigned through the attribute:”Add Css Layout Keywords”)
Second, modify the equation like follow:
(function(){
var a = fieldname24;
var tmp = fieldname25;
var c = fieldname26;
var result = 0;
jQuery( ‘.myclass input:checked’ ).each(function(){
var b = this.value;
if(a==1 && b==2) result += c*0.08;
if(a==3 && b==2) result += c*0.12;
});
return result;
})()
The equation is a little more complex, but the replacements are done only one time, and takes in consideration all options selected in the fieldname25 by separated.
If you need a customized equation, please, contact us through our suppor page:
http://wordpress.dwbooster.com/support
Best regards.