user510886
user510886

Reputation: 19

jQuery dialog will only open once

first my english not good so much. sory.

my problem is, when page load complete. i use click function first clik working successfully. but secon click not working. but i refresh the page first clik working , second not working againg. when i refresh the page code is working for once. (note: i am new at jquery )

$(document).ready(function () {
    $('#silmesaji').hide();
    $(".delbutton").click(function () {
        var element = $(this);
        var silinecek_idi = element.attr("id");
        var info = 'id=' + silinecek_idi;
        $("#silmesaji").dialog({
            modal: true,
            title: 'Kategoriyi Silin!',
            resizable: false,
            'buttons': {
                "Sil": function () {
                    $.ajax({
                        type: "GET",
                        url: "forms/joker.asp",
                        data: info,
                        success: function () { }
                    });
                    $("#silmesaji").dialog("close");
                    element.parents(".siralagayri").animate({
                        backgroundColor: "#f31e1f"
                    }, "fast").animate({
                        opacity: "hide"
                    }, "slow"); 
                },
                "iptal": function () {
                    $("#silmesaji").dialog("close");
                }
            }
        });
    });

firts thanks for answer.

but i want: when click OK button. sent post and close dialog. it can not work :(

$(".delbutton").click(function () {
    var element = $(this);
    var silinecek_idi = element.attr("id");
    var info = 'id=' + silinecek_idi;
    $("#silmesaji").dialog('open');
});


$("#silmesaji").dialog({
    autoOpen: false,
    modal: true,
    buttons: {
        "Ok": function() { 
            $.ajax({
                type: "GET",
                url: "forms/joker.asp",
                data: info,
                success: function(){ 
                    element.parents(".siralagayri")
                        .animate({ 
                            backgroundColor: "#f31e1f" 
                        }, "fast")
                        .animate({ 
                            opacity: "hide" 
                        }, "slow");
                    $("#silmesaji").dialog("close"); return false();
                }
            }); 
        }, 
        "Cancel": function() { 
            $(this).dialog("close"); 
        } 
    }
}); 

Upvotes: 1

Views: 2648

Answers (1)

GvS
GvS

Reputation: 52518

When calling $("#silmesaji").dialog(...), the default for the "autoOpen" option is true, so you create & show the dialog.

But after closing it, a call to $("#silmesaji").dialog(...), will not re-create the dialog, so it will also not "autoOpen".

You need to call $("#silmesaji").dialog('open'), to re-open/show the dialog.

I always do it like this:

  • In the ready function, I create the dialog, with autoOpen: false. (Note: not in the click event)
  • In the click event I call $("#silmesaji").dialog('open');

I will try to change your code:

$(document).ready(function () {
    $('#silmesaji').hide();
    $(".delbutton").click(function () {
        var element = $(this);
        var silinecek_idi = element.attr("id");
        var info = 'id=' + silinecek_idi;
        $("#silmesaji").dialog('open');
    });

    $("#silmesaji").dialog({
        autoOpen: false;
        modal: true,
        /* Your code */
    });


});

Upvotes: 1

Related Questions