How can I make something like that:
var string1 = "functionNameBeginning";
var string2 = "functionNameEnding";
element.innerHTML = string1 + string2 //string1 + string2 is name of function to execute
UPD: The thing that I wanted is to execute the function which is named string1string2()
, and the user Spencer Wieczorek understood me right in his comment about eval()
function. Also I really have found a better idea to solve this problem. Since it was the way that I wanted to use for processing select input
's value on Wordpress site:
<select name="formula" class="left-input" id="formula">
<option value="mifflin" selected>Mifflin-St Jeor</option>
<option value="harris">Harris–Benedict</option>
<option value="katch">Katch-McArdle</option>
</select>
I've written the function in my WP plugin:
if ($_POST['formula'] == 'mifflin') {
return mifflinFormula();
} else if ($_POST['formula'] == 'harris') {
return harrisFormula();
} else {
return katchFormula($_POST['fat']);
}