$(document).ready(function(){
    
    $('body').on("click", ".search", getCustomer);

    function getCustomer(){
        var custname    = $(".custname").val(),
                data    = {custname : custname},
                values  = "";
        
        $.ajax({
            type    : 'GET',
            dataType: 'json',
            url     : "getCust.php",
            data    : data,
            success : function (response) {
                $.each(response, function () {
                    values += "<tr>" +
                            "<input type='hidden' class='form-control accode'  name='accode_" + this.ctr + "' value='"+ this.accode+"'>" +
                            "<td align='right'><input type='text' class='form-control name'  name='name_" + this.ctr + "' value='"+ this.name+"' readonly></td>" +
                            "<td align='right'><input type='text' class='form-control city'  name='city_" + this.ctr + "' value='"+ this.city+"' maxlength='20'></td>"  +
                            "<td align='right'><input type='text' class='form-control station'  name='station_" + this.ctr + "' value='"+ this.station+"' maxlength='20'></td>" +
                            "<td align='right'><input type='text' class='form-control pin'  name='pin_" + this.ctr + "' value='"+ this.pin+"' maxlength='6'></td>" +
                            "<td align='right'><input type='text' class='form-control tel'  name='tel_" + this.ctr + "' value='"+ this.tel+"' maxlength='15'></td>" +
                            "<td align='right'><input type='numer' class='form-control mobile'  name='mobile_" + this.ctr + "' value='"+ this.mobile+"' maxlength='10'></td>" +
                            "<td align='right'><input type='numer' class='form-control text-right discount'  name='discount_" + this.ctr + "' value='"+ this.discount+"' ></td>" +
                            "<td align='right'><input type='numer' class='form-control text-right packing'  name='packing_" + this.ctr + "' value='"+ this.packing+"' ></td>" +
                            "<td align='right'><input type='numer' class='form-control text-right paid'  name='paid_" + this.ctr + "' value='"+ this.paid+"' ></td>" +
                            "</tr>";
                    $("#items").val(this.ctr);
                });
                $(".tbody").empty();
                $(".tbody").html(values);
            }
        });
    }
    
    getCustomer();
    
    
});