Result of $.post call in var

Result of $.post call in var

Hi all,

I'm stuck on something, someone can hopefully help me out with :) I want to store the returned data from an ajax call in a variable so that I can use it later in the script. But the following code gives an error;

  1. $('textarea').focus(function()
  2. {
  3.       var $this = $(this);
  4.       var  $id = 0;
  5.       $.post('getid.php',{ f_id: $('select:eq(0)').val() }, function(data)
  6.       {
  7.             if(data==="") { alert('no good'); } else { $id = data; }
  8.       });
  9.       alert($id); //gives error; undefined variable
  10. }
What I am doing wrong...? I'm pretty sure it's something stupid but I just can't see it right now... Anyone helping out? Thanks!