Page is a not externally linkable
- Code, Content, and Presentation
-- JavaScript and AJAX
---- inserting a variable into a function


Fotiman - 6:07 pm on Dec 3, 2012 (gmt 0)



I don't really want to run it via alert(). Is there an easier way?

I wasn't suggesting that... it was just a way to help you debug what is going on.

It runs perfectly if I hard-code the function name, like so:

function do_func() { pageFx("#ID", {setting: 'value', callback: do_func2_URLpage }); }

Ok, so it looks like it's expecting a function reference then. If your function is named "do_func2_URLpage", as in:

function do_func2_URLpage() {
//...
}

And you want to dynamically generate this function reference as opposed to statically passing it in, then you could use eval to do it like this:

callback: eval("do_func2_" + URL)

eval will evaluate a string as a script expression, thus converting the strings "do_func2_" and whatever is defined in URL (in this case, "URLpage"), into the expression do_func2_URLpage, which is the reference to your function.

Hope that works.


Thread source:: http://www.webmasterworld.com/javascript/4524548.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com