Call javascript function which name is in variable
17,073
Solution 1
window[name]()
You can call functions by name reference by selecting them as a property of window
and executing them
Solution 2
have you tried variableName();
?
We often pass around callback functions, which might look something like this
function doSomething(callbackFunction){
// some happy code
callbackFunction()
}
Related videos on Youtube
Author by
user769154
Updated on June 04, 2022Comments
-
user769154 almost 2 years
The problem is next: Assume that we have a select. Onchange event we need to call some function, but name of this function kept in variable. How to call this function ?
-
Andrew Winter almost 13 yearsSee this answer here. stackoverflow.com/questions/359788/…
-
-
Ray Toal almost 13 yearsActually, the OP said the name of the function is in the variable, not (a reference to) the function itself.
-
Dave Hilditch almost 11 yearsthis is what I was looking for - came up on Google for my search