Thursday, October 13, 2011

Passing data to jquery ui-dialog

I've always thought that passing of data to a dialog box in jquery is impossible. The only way to do this would mean setting a value to global variable and accessing it when ready. This post proves me wrong while browsing at stackoverflow.

jQuery provides a method which store data for you, no need to use a dummy attribute or to find workaround to your problem. Bind the click event:
$('a[href*=/Booking.aspx/Change]').bind('click', function(e) {
        .data('link', this)  // The important part .data() method
And your dialog:
    autoOpen: false,
    resizable: false,
    modal: true,
    buttons: {
        Cancel: function() {
        'Delete': function() {
            var path = $(this).data('link').href; // Get the stored result
            $(location).attr('href', path);

1 comment: