Welcome to the forum!
You're looking for javascript help, not PHP help. Ask a moderator to move your thread to the javascript section (don't cross-post).
Here is your cleaned-up javascript (there was a LOT of commented-out junk left in there and doing this cleanup will make things easier for someone to help you with the actual code at work - remeber this in future):
Code:
<script>
jQuery(document).ready( function($){
jQuery(".product-field-type-E").css("display","none");
vm_age_value=$(".vmcustomlist option:selected").text();
if(vm_age_value=='0'){
virtuemart_cf_formula = $('#show_values_formula').val();
virtuemart_cf_price = $('#show_values_product_price').val();
show_url=$("#show_url").val();
virtuemart_cf_split=String(virtuemart_cf_formula).split("{");
virtuemart_cf_f_cal=String(virtuemart_cf_split[1]).split("}");
calculation_operator=virtuemart_cf_f_cal[1];
virtuemart_cf_s_cal=String(virtuemart_cf_split[2]).split("}");
calculation_operator_s=virtuemart_cf_s_cal[1];
calculation_one_year=virtuemart_cf_s_cal[0];
var customval=$(".other-customfield").html();
var customvalue=String(customval).split("$");
var output='';
/* ---Calculation as per the formula admin- */
if(calculation_operator == '*' && calculation_operator_s == '+'){
output = parseInt(vm_age_value) * parseInt(calculation_one_year) + parseInt(show_url);
}
if(calculation_operator == '*' && calculation_operator_s == '-'){
output = parseInt(vm_age_value) * parseInt(calculation_one_year) - parseInt(show_url);
}
if(calculation_operator == '*' && calculation_operator_s == '*'){
output = parseInt(virtuemart_age_value) * parseInt(calculation_one_year) * parseInt(show_url);
}
if(calculation_operator == '*' && calculation_operator_s == '/'){
output = parseInt(vm_age_value) * parseInt(calculation_one_year) / parseInt(show_url);
}
/* ---- */
if(calculation_operator == '+' && calculation_operator_s == '+'){
output = parseInt(vm_age_value) + parseInt(calculation_one_year) + parseInt(show_url);
}
if(calculation_operator == '+' && calculation_operator_s == '-'){
output = parseInt(vm_age_value) + parseInt(calculation_one_year) - parseInt(show_url);
}
if(calculation_operator == '+' && calculation_operator_s == '*'){
output = parseInt(vm_age_value) + parseInt(calculation_one_year) * parseInt(show_url);
}
if(calculation_operator == '+' && calculation_operator_s == '/'){
output = parseInt(vm_age_value) + parseInt(calculation_one_year) / parseInt(show_url);
}
/* ---- */
if(calculation_operator == '-' && calculation_operator_s == '+'){
output = parseInt(vm_age_value) - parseInt(calculation_one_year) + parseInt(show_url);
}
if(calculation_operator == '-' && calculation_operator_s == '-'){
output = parseInt(vm_age_value) - parseInt(calculation_one_year) - parseInt(show_url);
}
if(calculation_operator == '-' && calculation_operator_s == '*'){
output = parseInt(vm_age_value) - parseInt(calculation_one_year) * parseInt(show_url);
}
if(calculation_operator == '-' && calculation_operator_s == '/'){
output = parseInt(vm_age_value) - parseInt(calculation_one_year) / parseInt(show_url);
}
/* ---- */
if(calculation_operator == '/' && calculation_operator_s == '+'){
output = parseInt(vm_age_value) / parseInt(calculation_one_year) + parseInt(show_url);
}
if(calculation_operator == '/' && calculation_operator_s == '-'){
output = parseInt(vm_age_value) / parseInt(calculation_one_year) - parseInt(show_url);
}
if(calculation_operator == '/' && calculation_operator_s == '*'){
output = parseInt(vm_age_value) / parseInt(calculation_one_year) * parseInt(show_url);
}
if(calculation_operator == '/' && calculation_operator_s == '/'){
output = parseInt(vm_age_value) / parseInt(calculation_one_year) / parseInt(show_url);
}
net_output="$"+output;
$('.vmcustom-textareainput').val(net_output);
}
jQuery('.vmcustom-textareainput').css('display','none');
jQuery('.vmcustomlist').change(function(){
formProduct = $(this).parents('form.product');
virtuemart_cf_id = $('#show_values_cfId').val();
nameOfCF = "customPlugin["+virtuemart_cf_id+"][textinput][comment]";
inputCF='\'input[name="'+nameOfCF+'"]\'';
virtuemart_age_value = $(".vmcustomlist option:selected").text();
virtuemart_cf_formula = $('#show_values_formula').val();
virtuemart_cf_price = $('#show_values_product_price').val();
show_url=$("#show_url").val();
virtuemart_cf_split=String(virtuemart_cf_formula).split("{");
virtuemart_cf_f_cal=String(virtuemart_cf_split[1]).split("}");
calculation_operator=virtuemart_cf_f_cal[1];
virtuemart_cf_s_cal=String(virtuemart_cf_split[2]).split("}");
calculation_operator_s=virtuemart_cf_s_cal[1];
calculation_one_year=virtuemart_cf_s_cal[0];
var customval=$(".other-customfield").html();
var customvalue=String(customval).split("$");
var output='';
/* ---Calculation as per the formula admin- */
if(calculation_operator == '*' && calculation_operator_s == '+'){
output = parseInt(virtuemart_age_value) * parseInt(calculation_one_year) + parseInt(show_url);
}
if(calculation_operator == '*' && calculation_operator_s == '-'){
output = parseInt(virtuemart_age_value) * parseInt(calculation_one_year) - parseInt(show_url);
}
if(calculation_operator == '*' && calculation_operator_s == '*'){
output = parseInt(virtuemart_age_value) * parseInt(calculation_one_year) * parseInt(show_url);
}
if(calculation_operator == '*' && calculation_operator_s == '/'){
output = parseInt(virtuemart_age_value) * parseInt(calculation_one_year) / parseInt(show_url);
}
/* ---- */
if(calculation_operator == '+' && calculation_operator_s == '+'){
output = parseInt(virtuemart_age_value) + parseInt(calculation_one_year) + parseInt(show_url);
}
if(calculation_operator == '+' && calculation_operator_s == '-'){
output = parseInt(virtuemart_age_value) + parseInt(calculation_one_year) - parseInt(show_url);
}
if(calculation_operator == '+' && calculation_operator_s == '*'){
output = parseInt(virtuemart_age_value) + parseInt(calculation_one_year) * parseInt(show_url);
}
if(calculation_operator == '+' && calculation_operator_s == '/'){
output = parseInt(virtuemart_age_value) + parseInt(calculation_one_year) / parseInt(show_url);
}
/* ---- */
if(calculation_operator == '-' && calculation_operator_s == '+'){
output = parseInt(virtuemart_age_value) - parseInt(calculation_one_year) + parseInt(show_url);
}
if(calculation_operator == '-' && calculation_operator_s == '-'){
output = parseInt(virtuemart_age_value) - parseInt(calculation_one_year) - parseInt(show_url);
}
if(calculation_operator == '-' && calculation_operator_s == '*'){
output = parseInt(virtuemart_age_value) - parseInt(calculation_one_year) * parseInt(show_url);
}
if(calculation_operator == '-' && calculation_operator_s == '/'){
output = parseInt(virtuemart_age_value) - parseInt(calculation_one_year) / parseInt(show_url);
}
/* ---- */
if(calculation_operator == '/' && calculation_operator_s == '+'){
output = parseInt(virtuemart_age_value) / parseInt(calculation_one_year) + parseInt(show_url);
}
if(calculation_operator == '/' && calculation_operator_s == '-'){
output = parseInt(virtuemart_age_value) / parseInt(calculation_one_year) - parseInt(show_url);
}
if(calculation_operator == '/' && calculation_operator_s == '*'){
output = parseInt(virtuemart_age_value) / parseInt(calculation_one_year) * parseInt(show_url);
}
if(calculation_operator == '/' && calculation_operator_s == '/'){
output = parseInt(virtuemart_age_value) / parseInt(calculation_one_year) / parseInt(show_url);
}
if(virtuemart_age_value!=""){
net_output="$"+output;
$('.vmcustom-textareainput').val(net_output);
}
});
});
</script>
Note that I am focusing onthe highlighted section of the code above, as that is the portion that "calculates" your formula when you change it in the page. I am not even going to bother looking into the calculation that runs on page load because it looks almost identical anyway and I don't think it is the focus of your question.
That said, the script basically pulls in your formula to the variable "virtuemart_cf_formula" and then splits the string a number of different ways in order to isolate operators and values, and then it uses a couple of values obtained from a select element and an input element to do some math.
As far as I can see, there is no code in there at all to actually pay attention to what names you have listed in your formula. In fact, the script only supports the use of numbers (not names or any non-numeric data) in the forumla anyway. Further, this script is not set up to use a flexible number of calculation pieces at all. It will only ever accept two operators and it will only ever pay attention to the value in the second set of curly braces (which, again, MUST be a number for this script to work at all - more on this later). If you paid any money to the coder who wrote this for you I'd recommend you try to get it back immediately. This script does not appear to do what you say it should do, and this is a good reason NOT to use the cheapest off-shore coder you can find to do some work (admittedly, an assumption based on the language barrier you mention - but we see a lot of this in the forum).
So, here is the bottom line:
This script only supports the use of two operators at a time (you can see this with all of the
if(calculation_operator == '*' && calculation_operator_s == '+'){ tests in the list of "if" statements)...there is no array being passed for checking, and no recursion...only two operators are being tested...ever. And whatever your values are here:
{Product_Age}+{1}*{Product_Value} is irrelevant because the script never does anything with them in this formula. It never even isolates them as values, which in this context would be done with
virtuemart_cf_f_cal[0] and
virtuemart_cf_split[3] , respectively (though hard-coding this index into the script means, again, that the script is not flexible in its number of inputs and operators). Even if you were to hard-code those items the script would still need to be updated to actually use them, so that's still not a very quick fix. The script only picks out the first two operators, and then produces a calculation basically consisting of this process:
"show_url" value <first operator> value in the SECOND curly braces <second operator> "virtuemart_age_value" value
Edit: To illustrate this fact, you can add this line right before the list of "if" statements in the change function:
Code:
alert(parseInt(virtuemart_age_value)+" "+calculation_operator+" "+parseInt(calculation_one_year)+" "+calculation_operator_s+" "+parseInt(show_url));
That will alert the formula being used to generate the final result, and unless I have made a mistake, if you hand-calculate what appears in the alert box it should come out to the same result you are given in the page. This will also show where the NaN error comes into play if your formula has a non-numeric value for the second curly braces.
So in the case of your first example formula the script just multiplies the value of "show_url" by whatever numeric value is in the SECOND curly braces, and then adds the value of "virtuemart_age_value" to the result (since the first operator was a multiplication operation and the second one was addition). If you reverse the order of the operators it adds "show_url" to the product of the value in the second curly braces and the value of "virtuemart_age_value" (in other words, javascript automatically follows the standard "order of operations" and this script merely moves around the */+- operators to fit whichever order they appeared in the formula you enter).
If this script ever produced a correct result for you then it was probably a coincidence.
In response to your specific issue, since the second thing in curly braces is a string when you use the forumla
{10}-{Product_Age}/{10}*{Product_Value} you are attempting to perform mathematics on a string and are receving a NaN error as your output. It only continued to "work" when numbers were added to the middle of the formula because those items were still numeric and/or the "1" was still in the second set of curly braces - you can literally add anything you want in curly braces after that second set of curly braces and the script will still run.
This script cannot be "tweaked" into working the way you want it to work, and it really needs a complete restart. Sorry for the bad news!