Javascript/jQuery: Replace items in string matching {x} with "jQuery('#resultsx').val()" -
I have a string that contains a formula, such as
{1} + { 2} - {3} * {4}
I have different input fields such as
It will be as such
15 + 25-35 * 45
which will then calculate -1535
Hopefully I have clarified what I want to do clearly but let me know that I am not. I have tried to use regexps, but my head does not get completely around it and I'm not sure that this direction should go to me.
2 can take a function as a parameter that will help here:
var equ = '{1} + {2} - {3} * {4}'; Equ = equ.replace (/ {(\ d +)} / g, function (match, $ 1) {return $ ('# result' + $ 1) .val ();});
Comments
Post a Comment