$(document).ready(function() {
$('table#example').on('keyup', '#quantity', function(){
  var fiyat =  $(this).attr('data-id');
  $(this).closest('tr').toggleClass('secili');
  hesapla();
});
  

  function post() {
      var x = new Array();
  	$('table#example .secili').each(function(){
      	var f = parseInt($(this).find('td').eq(0).find('input').val());
        if (!isNaN(f) && f>0) {
          x.push(new Array(
          	$.trim($(this).find('td').eq(1).html()),
            f,
            $.trim($(this).find('td').eq(4).html())
          ));
        }
      });
     alert(JSON.stringify(x));
  }
  
  $('#sub').bind('click',function(){post()});

 function hesapla() {
  toplam = 0;
  $('table#example .secili').each(function(){
    var f = $(this).find('td').eq(4).html();
    var f1 = f.replace("$","");
    var f2 = f1.replace(".", "");  
   
    f2 = parseInt(f2);
    var adet = $(this).find('input').eq(0).val();
    
    var ucret = f2 * parseInt(adet);

    toplam = toplam + ucret;
    var nm = numeral(toplam).format('$0,0.00').toString();
    
    $("#sub").html(nm);
  });
  
  
}
   });