$(document).ready(function() {
    $("#course").change(function() {
        var course = $(this).val();
        if(course !== "") {
            $.ajax({
            url:"exam-results.php",
            data:{c_id:course},
            type:'POST',
            success:function(response) {
              var resp = $.trim(response);
              $("#yos").html(resp);
            }
        });
        } else {
          $("#yos").html("<option value=''>- Select YoS -</option><option value='' class='bg-danger text-danger'>Failed to read years of study</option>");
        }
    });
    
    
    $("#course").change(function() {
        var course = $(this).val();
        if(course !== "") {
            $.ajax({
            url:"exam-results.php",
            data:{cid:course},
            type:'POST',
            success:function(response) {
              var resp = $.trim(response);
              $("#classYear").html(resp);
            }
        });
        } else {
          $("#yos").html("<option value=''>- Select YoS -</option><option value='' class='bg-danger text-danger'>Failed to read years of study</option>");
        }
    });

        
    $("#yos").change(function() {
        var yos_id = $(this).val();
        var course = $('#course').val();
        
        if(yos_id !== "") {
            $.ajax({
            url:"exam-results.php",
            data:{yoss:yos_id,cos:course},
            type:'POST',
            success:function(data) {
              var result = $.trim(data);
              $("#unit").html(result);
            }
        });
        } else {
          $("#unit").html("<option value=''>- Select Unit -</option><option value='' class='bg-danger text-danger'>Failed to identify units</option>");
        }
    });
  
});
     
        