469,276 Members | 1,746 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,276 developers. It's quick & easy.

Dynamically call a function

For the project I'm working on, I need to dynamically call one of several functions (which are dynamically named by asp.net). How do I call a function when I have the function name in a string? A case statement is not an option, because the function names are dynamic.
Expand|Select|Wrap|Line Numbers
  1. function function1() {
  2.    ...
  3. }
  4. function function2() {
  5.     ...
  6. }
  7. var functionName = 'function1'
  8.  
...what next?

How do I execute the function whose name is stored in functionName?

Thanks
Sep 24 '09 #1
3 3175
gits
5,390 Expert Mod 4TB
when the functions are declared in the window-scope then you might use:

Expand|Select|Wrap|Line Numbers
  1. window['yourFunctionName']();
to call the function.

kind regards
Sep 25 '09 #2
Thanks. I figured there was a pretty easy way to do it.
Sep 25 '09 #3
gits
5,390 Expert Mod 4TB
no problem ... in case you would have more questions just post back to the forum ...

kind regards
Sep 25 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Ola Fjelddahl | last post: by
2 posts views Thread by Joe | last post: by
8 posts views Thread by Falc2199 | last post: by
11 posts views Thread by Steven D'Aprano | last post: by
2 posts views Thread by Claire | last post: by
11 posts views Thread by onkar.n.mahajan | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.