views:

113

answers:

2

for example I call it via newDialog("This is title !", "this is my content");

function newDialog(mytitle, mycontent){
   var $dialog = $('<div id="mydialog"></div>')
        .html(mycontent)
        .dialog({
            autoOpen: false,
            modal: false,
            title: mytitle
        });
    $dialog.dialog('open');
    return false
}

This is the error

Error: $("").html(mycontent).dialog is not a function

What does this mean ? I have made sure all the jquery-UI, and jquery js files are fully loaded using firebug plugin to confirm all of this.

I don't understand why it would suddenly stop working.

I've tried it with $(document).click(newDialog); and $('body').delegate(':not(#mydialog *, #mydialog)','click', newDialog); but the error is not going away. The latter is used so new dialogs will not spawn if the dialog is accidently clicked.

$(top.document).ready(function () {   
var fruits = new Array();

   $(document).click(newDialog("happy title", "happy content to keep everyone happy"));
   //$('body').delegate(':not(#mydialog *, #mydialog)','click', newDialog);

});
+4  A: 

For updated question: You still have the same issues as bfeore, when calling it like this:

$(document).click(newDialog);

It's being called without any parameters, which means .html() is still getting undefined passed in. You eiher need to pass parameters, e.g.:

$(document).click(function() { newDialog("Title", "Content"); });

Or give the parameters some defaults, for example:

function newDialog(mytitle, mycontent){
  mytitle = mytitle || "Default Title";
  mycontent = mycontent || "Default Content";

For original question: Your variables names are off, this:

.html(mycontent)

Should be:

.html(mycon)

Currently, since it's undefined, it's calling .html() getting a string back, not setting the html. The same is true for the title, your parameter is mytit, the variable you're trying to use is mytitle.

Nick Craver
unfortunately I wish this was a simple var naming problem. I made sure same variables are used, and same error occurs.
Kim Jong Woo
@Kim - In these cases you're still passing no parameter, meaning it's *still* undefined, resulting in the same error, you have to actually pass the `mycontent` parameter, or give it a default...it'll be `undefined` otherwise. I appreciate the downvote...you're dismissing the answer *after* you corrected one facet here, but you still have the **same** problem, you're passing `undefined` to `.html(var)`.
Nick Craver
sigh. I wrote that quick example and didn't write it properly. which is why you are addressing the wrong problem. my bad, fixed the original example code. however the error still ensues. I don't know why it's almost like jquery-ui.js is not loaded but firebug shows it has.
Kim Jong Woo
@Kim - Did you read my updated answer? It's the same issue, the variable being passed to `.html(var)` is `undefined`, even in your current question. Also when you downvote have a reason, the *question* being wrong (when the answer fixes *that* question) isn't really a valid reason, and will drive people off from answering your questions in the future :)
Nick Craver
I downvoted because you were stating the obvious and not reallly addressing the intended problem. However, it was badly written example, so I see why you are angry since you did provide a correct solution to the poorly written example. In the end, nothing is solved. I have upvoted anyways but won't be accepting this answer as it is right now.
Kim Jong Woo
@Kim - Your updated question is calling it *immediately*, you still need an anonymous function passed as the `click` handler, like in my answer.
Nick Craver
resolved it. it was the original applications fault, i've run my script on several other applications and it runs fine.
Kim Jong Woo
I appreciate your help however, in the end, this answer is not really reflective of the potential solution I ahve been searching since there was no problem with my original code (not the example one I wrote here which obviously has had mistakes and you've correctly fixed them).
Kim Jong Woo
A: 

Check that the dialog plugin is properly installed. There shouldn't be any other reason why this shouldn't work.

May I take this opportunity for some shameless self-promotion to offer you an alternative. I wrote a jQuery plugin that does what you are trying to do. It's open source if you are interested: http://mosttw.wordpress.com/2010/08/07/dialogwrapper-simplified-use-of-jquery-ui-dialogs/

SimpleCoder
you are correct. but dialog plugin is correctly installed.
Kim Jong Woo
you know I am always open to better solutions. Thanks for the suggestion will have a look at it. You were right, there shouldn't be any other reason why this shouldn't work, and yes, it was no the code but simply the javascript running on another application, the application itself was causing issues. tested teh same javascript in other places and it runs fine !
Kim Jong Woo