$(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+"'></td>" +
                            "<td align='right'><input type='text' class='form-control pin'  name='pin_" + this.ctr + "' value='"+ this.pin+"'></td>" +
                            "<td align='right'><input type='text' class='form-control tel'  name='tel_" + this.ctr + "' value='"+ this.tel+"'></td>" +
                            "<td align='right'><input type='text' class='form-control mobile'  name='mobile_" + this.ctr + "' value='"+ this.mobile+"'></td>" +
                            "<td align=''><input type='text' class='form-control state'  name='state_" + this.ctr + "' value='"+ this.state+"'></td>" +
                            "<td align=''><input type='text' class='form-control statecode'  name='statecode_" + this.ctr + "' value='"+ this.statecode+"'></td>" +
                            "<td align=''><input type='text' class='form-control gstno'  name='gstno_" + this.ctr + "' value='"+ this.gstno+"'></td>" +
                            "</tr>";
                    $("#items").val(this.ctr);
                });
                $(".tbody").empty();
                $(".tbody").html(values);
            }
        });
    }
    
    getCustomer();
    
    
});