$(document).ready(function () {
    $("body").on("change", ".product", getprodcode);
    $("body").on("blur", ".prodcode", getproduct);


    function getproduct() {
        var prodcode = $('.prodcode').val();
        if (prodcode != '') {
            $.post('getproduct.php', {prodcode: prodcode}, function (data) {
                $('.product').val(data.name);
                $('.product').trigger('change');
            }, 'json');
        }
    }

    function getprodcode() {
        var product = $('.product').val();
        if (product != '') {
            $.post('getprod.php', {product: product}, function (data) {
                $('.prodcode').val(data.prodcode);
                $('.prodcode').trigger('change');
            }, 'json');
        }
    }
});