$(function()
{
  $('#id_category').change(function(event)
  {
    id = $('#id_category').attr('value');
    if(id!=0)
    {
      $.ajax(
      {
        url     : '/ajax/update_type_loan.html',
        type    : 'POST',
        data    : 'id_category='+id,
        success : function (response)
          {
              var types = $.parseJSON(response);
              n= types.length;
              newOptions = Array(n);

              id_type = $('#id_type');
              $('option', id_type).remove();

              options = id_type.attr('options');

              for(i=0;i<n;i++)
              {
                options[i] = new Option(types[i].name_type_loan, types[i].id_type_loan);
              }
              
              id_type.removeAttr('disabled');
          }
      })
    }
    else
    {
      id_type = $('#id_type');
      $('option', id_type).remove();
      options = id_type.attr('options');
      options[0] = new Option('Select Loan Type',0);
      id_type.attr('disabled', 'disabled');
    }
  });
});




