$(document).ready(function () {
    $("body").on("blur change", ".school", getscode);
    $("body").on("blur", ".custcode", getccode);

    function getscode() {

        var school = $('.school').val();
        if (school != '') {
            $.post('getscode.php', {school: school}, function (data) {
                $('.custcode').val(data.custcode);
            }, 'json');
        }
    }

    function getccode() {
        var custcode = $('.custcode').val();
        if (custcode != '') {
            $.post('getccode.php', {custcode: custcode}, function (data) {
                $('.school').val(data.name);
                $('.school').trigger('change');
                $('.medium').val(data.medium);
                $('.medium').trigger('change');
            }, 'json');
        } 
    }

});