Passing value to jQuery UI Dialog for AJAX post on confirmation -
i'm using jquery ui dialog confirm delete request. i'm trying pass in id ajax post when user confirm deletion request. thank in advance insight.
here html:
<table width="100%" cellspacing="1" cellpadding="5" border="0" class="detailtbl" id="mytable"> <tbody> <tr class="divider" id="editrow220"> <td align="top">lorem ipsum dummy text of printing , typesetting industry. </td> <td align="top"> <a class="btn_delete deleteme form-tip" href="#" id="220" title="delete item"></a> <span>lorem ipsum dummy text of printing , typesetting industry. </span> </td> </tr> </tbody> </table>
here script:
$("#mytable tbody").on("click", "a.deleteme", function (e) { e.preventdefault(); var removeid = $(this); alert(removeid.attr("id")); // ***correct id here *** var $mydialog = $('<div></div>') .html('are sure want delete item?') .dialog({ autoopen: false, title: 'confirmation', buttons: {"yes": function(e) { alert(removeid.attr("id")); // ***removeid undefined here*** // ajax call here // return true; }, "no": function() { $(this).dialog("close"); return false; } } }); return $mydialog.dialog('open'); });
this may sloppy solution, can try assigning id global variable, using it:
var mid; $("#mytable tbody").on("click", "a.deleteme", function (e) { e.preventdefault(); mid = $(this).attr("id"); var $mydialog = $('<div></div>') .html('are sure want delete item?') .dialog({ autoopen: false, title: 'confirmation', buttons: {"yes": function(fmopmotoremove) { alert(mid); //shouldnt undefined anymore ..rest of code..
Comments
Post a Comment