santa
santa

Reputation: 12512

Pass value into dialog window in jQuery UI and to AJAX

I have a number of items on a page that when clicked trigger UI's modal dialog.

var $dialog = $("#dialog").dialog({ 
    autoOpen: false,
    resizable: false,
    modal: true 
});

$(".myLink").click(function(){
    $dialog.dialog("open");
    $("#dialog").dialog({
    var delURL = $(this).attr("href").split("#");
    var delID  = delURL[1]; 
        buttons: {
            "Delete": function() { 
                // need to add AJAX call here
                $.ajax({
                    type: "POST",
                    url: "some.php",
                    data: "delete=delID",
                    success: function(msg){
                        alert( "Deleted: " + msg );
                    }
     });
                $(this).dialog("close"); 
            }, 
            "Cancel": function() { 
                $(this).dialog("close"); 
            } 
        }
    });
});

I need to pass anchor value to another page when "Delete" button is clicked. I thini I need to use AJAX.

<a href="#val_1" class="myLink">Value 1</a>
<a href="#val_2" class="myLink">Value 2</a>
<a href="#val_3" class="myLink">Value 3</a>

Not sure how to do it.

Upvotes: 2

Views: 1629

Answers (2)

Arihant Nahata
Arihant Nahata

Reputation: 1810

I think you just need to change

data: "delete=delID",to <br />
data: "delete="+delID,

Upvotes: 2

Ekim
Ekim

Reputation: 1105

try changing the line

$(".myLink").click(function(){
to
$(".myLink").live("click", function() {
however there is a bug in the lines when I test it. To get the dialog you should move the lines
    var delURL = $(this).attr("href").split("#");
    var delID  = delURL[1]; 

above

    $dialog.dialog("open");

Upvotes: 1

Related Questions