The following worked for me (IE 6, FF2):

function lock (){ alert(0); }
var str = 'lock';
alert (window[str]);
(window[str])();

first alerted the function definition, then executed the function.

So it seems that window[click_func] is the function itself; don't
append () when passing it to bind.

Danny

On Oct 16, 11:32 am, Mark Lacas <[EMAIL PROTECTED]> wrote:
> Hello,
>   I'm stuck on a silly detail.
>
> I want to bind a click to a function whose name is a simple string in
> a variable from a database
>
> I've tried a number of different syntactical combinations but none
> seem to work.
>
> Here is my code:
>
> $( ".object" ).each( function() {
>         var element = this;
>         var click_func = $( "#"+element.id +
> " .dp_properties").attr("dp_click_func");
>
>         if ( typeof( click_func ) != "undefined" ) {
>                 $(element).bind( "click", click_func );          // This 
> doesnt'
> work, it's a function name from a database
>         } else {
>                 $(element).bind( "click", click_handler );     // This does 
> work,
> it's a predefined function
>         }
>
> });
>
> The function name that I'm using in click_func is called lock and the
> function is predefined in my base javascript.
>
> I tried calling it by using window[click_func](), click_func+"()" and
> other assorted methods.  No luck.
>
> I'm sure this is vary simple and I will slap my head when it gets
> figured out.
>
> Thanks,
> m

Reply via email to