1

I use the JQuery dialog and from the PHP I can build some add-in to the button. To be able to add code from the server side I pass a method by parameter. The problem is that FireBug tell me that the method is not defined :

alt text

okHandler is the parameter of this method call to raise the dialog and it contain a simple alert message for the moment, later some Ajax calls. Any idea why it doesn't work?

alt text

1
  • 1
    Can you provide some more context? Where is okHandler defined? Commented Jan 27, 2010 at 2:07

3 Answers 3

4

It looks like okHandler is a string containing a function declaration, not an actual function? You have

okHandler = "function anonymous(){alert('This is a test');}";

instead of

okHandler = function(){alert('This is a test');};
Sign up to request clarification or add additional context in comments.

Comments

0

As John Kugelman notes, okHandler appears to be a string. It would work better if it was a function... However, if a string it must be, then you'll need to pass it through eval() to actually execute it:

eval( "(" + okHandler + ")()" )

1 Comment

+1 it works with eval but in fact I was passing a String from the Server side to the client side. I gave you +1 but will accept John answer. Thanks Shog9
0

Is the okHandler() function loaded (as a valid JS object -- not a String) at the time you get that error?

I believe it's not alright to call something like "if (foo != null)" if foo hasn't already been declared as a variable somewhere. FireBug would complain: "okHandler is no defined."

Try something like this...

var myHandlers = {};
// Load okHandler as a member of myHandlers when applicable here...
$('#dialog'+idbox)...
    "Oky": function() {
        myHandlers.okHandler && myHandlers.okHandler();
        ...
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.