Bill Greer
Bill Greer

Reputation: 3156

jQuery Dialog Not Closing

My alert is reached and works, but the close method is not working. Any idea why ?

My javascript:

  var myDialog = $('#divContactUs');

  myDialog.dialog({
               autoOpen: false,
               title: "Send Us A Note:",
               modal: true,
               buttons: [{
                   id: "btn-send",
                   text: "Send",
                   click: function () {
                       // you can now use the reference to the dialog
                       myDialog.dialog("close");
                       alert('test');
                   }
               }]

           });
       });

And my html:

<div id="divContactUs" style="display:none">
Name: &nbsp <input type="text" name="Name" /><br />
Email: &nbsp <input type="text" name="Email" /><br />
Phone: &nbsp <input type="text" name="Phone" /><br />
Message:<br />
<textarea name="Message"></textarea>
</div>

Upvotes: 2

Views: 6258

Answers (3)

codemirror
codemirror

Reputation: 3572

Sometimes IE throws an error "Unspecified Error".

try{ 
    $(selector).dialog("close");.
}catch(e){
    $(selector).parent().hide();
}

Upvotes: 0

L105
L105

Reputation: 5419

You script is working. Don't forget to add semicolon ; add the end of your lines $(this).dialog("close");.

Here's a jsFiddle to prove it JsFiddle

Upvotes: 0

Jivings
Jivings

Reputation: 23250

In the scope of the button click $(this) refers to the button, not the modal. I would set the modal selector to a variable first then reference it later;

var myDialog = $('#divContactUs');

myDialog.dialog({
    autoOpen: false,
    title: "Send Us A Note:",
    modal: true,
    buttons: [{
        id:"btn-send",
        text: "Send",
        click: function() {
            // you can now use the reference to the dialog
            myDialog.dialog("close")
        }
    }
});

Upvotes: 2

Related Questions