Alex's code was doing the equivalent of:

$(".btnSave").click("editElementNameSave");

The click() function, like all event functions, expects to receive a
*reference* to a function, not the *name* of a function.

Your code is doing the equivalent of:

"editElementNameSave"();

You can't call a string as if it were a function.

If editElementNameSave() is a global function (not nested inside another
function), you can do:

$(".btnSave").click( window[handler+'Save'] );

Alex, if you could explain the purpose of the code and give a more complete
example, there may be a better way to do it.

-Mike

> From: jQuery Lover
> 
> I have tried this:
> ========================
> var handler = "editElementName";
> function editElementNameSave()
> {
>       alert('Hurray!');
>       console.log(1);
> }
> function showModalBox(handler)
> {
>       $(".1").click(function(){
>               console.log(2);
>               (handler + "Save")();
>       });
>       console.log(3);
> }
> $(document).ready(function(){
>       showModalBox(handler);
> });
> ========================
> 
> And I got "editElementNameSave is not a function" error !!!
> 
> Error refers to line -> (handler + "Save")();
> 
> ----
> Read jQuery HowTo Resource  -  http://jquery-howto.blogspot.com
> 
> 
> 
> On Thu, Jan 22, 2009 at 1:15 PM, Alex Sergeev 
> <sergeev.sa...@gmail.com> wrote:
> >
> > Hello!
> >
> > i have a code
> >
> > var handler = "editElementName";
> > function showModalBox(width, height, handler, id) { ...
> > $(".btnSave").click(handler + "Save"); ...
> > }
> >
> > function editElementNameSave(e)
> > {
> > alert(1);
> > }
> >
> > Why dont work event click?
> >
> > PS sorry for my English - i am from Russia
> >
> 

Reply via email to