views:

449

answers:

2

I have the below code for my a Dialog box for a which contains a dropdown field

KPMS.ServiceRequests.Status = {

 showOptions : function(requestId, userId, requestType) {
  var url = BASE_URL+'service_requests/status_options/';

        $("#dialog-modal").dialog("destroy");
  $("#dialog-modal").load(url, {"request_id": requestId, "user_id": userId, "request_type":requestType}).dialog(
   {
    modal: true,
    title: "Update Status",
    buttons: {
     Cancel : function() {
      $(this).dialog('close');
     },
     Update: function() {
      alert(1);
     }
    }
   }
  );    
 }
}

There is an anchor tag to populate the Dialog

<a onclick="KPMS.ServiceRequests.Status.showOptions(9, 11, 'SR'); return false;" title="Update status" href="http://localhost/kitco/pms/#9"&gt;&lt;img alt="[E]" title="Update" src="http://localhost/kitco/pms/images/edit.png"&gt;&lt;/a&gt;

My problem is When i click the link for the first time the dialog box is populating properly. Then I closed the dialog using the cancel button, then again clicked the link to open the dialog and closed it. For the third click on the link I'm getting the below Javascript error, and Dialog box is not opened

Error: b("<div></div>").addClass("ui-widget-overlay") is undefined
Source File: http://localhost/kitco/pms/js/jquery-ui-1.8rc3.custom.min.js
Line: 199

How to solve this problem?

+1  A: 

Does it really say b? Should that not be $ or jQuery?

EDIT: nevermind, it's an internal jQuery call, so that explains the b. b should be an alias to the jQuery object (var b = this), so that means the div creation is working, but that addClass is not / is returning undefined.

Are you sending your document as application/xhtml+xml, perchance? I have had a lot of trouble with jQuery 1.4 and jQuery UI 1.8 when using XTML, not HTML. Just a hunch.

janmoesen
+4  A: 

why do you keep destroying and rebuilding the dialog why not just build the dialog once and load/change the content of the dialog div ? I think that should solve the problem

mcgrailm
Amazing! this one really worked!
Mithun P
I thought it might do the trick I tried using destroy before and found this method to be better
mcgrailm