I have the following code which is run at the end of a long table that has several button.enter-match elements:
$("button.enter-match")
.button()
.on('click', function() {
    $("form.enter-match").dialog({
        modal: true,
        height: 'auto',
        width: 200,
        close: function() {
            $("form.enter-match input[name='code']").val('');
        },
        open: function() {
            $("form.enter-match input[name='code']").val('').focus();
        },
        buttons: {
            Set: function() {
                pid = $(this).parents("[data-pid]").data('pid');
                if ($("form.enter-match input[name='code']").val() == '') {
                    alert('Code empty!');
                    return false;
                }
                $.post(
                    request_url,
                    {
                        'action': 'set_match',
                        'pid': pid,
                        'code': $("form.enter-match input[name='code']").val()
                    },
                    function (data) {
                        error_handler(data);
                        if (data['error'] == null) {
                            $("tr#pid-" + pid + " td.code:first div").html('<i>' + $("form.enter-match input[name='code']").val() + '</i>');
                            $("form.enter-match").dialog('close');
                        }
                    },
                    'json'
                );
            }
        }
    });
});
The line pid = $(this).parents("[data-pid]").data('pid'); does not get the pid data value because form#enter_match is created at the very top of the document to be reused in the code as needed. It therefore will not have a parent with the [data-pid] attribute, however, button.enter-match will. How do I get the value in [data-pid] for this particular button.enter-match from within the $("form.enter-match").dialog() portion of the code?
