Global variable not setting

Global variable not setting

Hi,

Here is a snippet of my code, not complete, but shows the areas in question. I have defined var id on before anything this gets defined then set it on line 5 ... it's the table's row ID. I want to access this in line 17 but it says undefined, I just can't think why any clues?

  1.  $(document).ready(function() {
  2. var id;
  3. $('.comment').click(function() {
  4.             $('#dialog').dialog('open');
  5.             id = $(this).closest('tr[id]').attr('id');
  6.            
  7.         });

  8.  $('#submitcomment').click(function() {
  9.             var dataString = $('textarea#comment').val();
  10.             $.ajax({
  11.                 type: "POST",
  12.                 url: "showrota.php",
  13.                 data: { message: dataString},
  14.                 success: function() {
  15.                     $('#dialog').dialog('close');
  16.                     showMessage('#53FF38', 'black', 'Comment Added' + id );
  17.                 }
  18.             });
  19.             return false;
  20.         });

Thanks