Why won't this var change value?

Why won't this var change value?

So I have this jquery code and it works except for one specific part. I am doing a quantity check for a shopping cart system and I need to prevent the default form submission of the submit button and check all the quantities with a $.post() and checking the database. I have confirmed that all aspects work for the checking and outputting to the screen when and where they need to. If I alert(bad) inside the else{} it shows me the value I expect but it does not seem to hold that value or something after the .each() runs which is where I check it's value and submit the form if it's still false in value. Any insight would be great.
  1.     
    1. $('#paypal-submit-button').click(function(e){
    2.         var bad = false;
    3.         e.preventDefault();
    4.         $('.qty-input').each(function(){
    5.             var qty = parseInt($(this).val());
    6.             var id = parseInt($(this).attr('prod_id'));
    7.             var qty_id = String($(this).attr('qty-input-num'));
    8.             
    9.             $.post('check_avail_qty.php', {pid:id, quantity:qty}, function(data){
    10.                 if(data == "good")
    11.                 { }
    12.                 else
    13.                 {
    14.                     $('#prod-qty-check'+qty_id).html('Oh No! It seems we have run out of this item. Please remove it from your cart to continue.');
    15.                     var bad = true;
    16.                     alert(bad);
    17.                 }
    18.             });
    19.         })
    20.         if(bad === false){ $('#cart-submit-form').submit(); }
    21.     });