Spaces:
Sleeping
Sleeping
File size: 1,281 Bytes
888fff2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
$(document).ready(function() {
// Function to load courses based on the selected zone
function loadCourses(zone) {
$.ajax({
url: '/get_courses', // Make sure this route exists in Flask
method: 'POST',
contentType: 'application/json',
data: JSON.stringify({ 'zone': zone }),
success: function(response) {
// Clear the existing options in the course dropdown
$('#course').empty();
// Populate the course dropdown with the new options
response.forEach(function(course) {
$('#course').append(new Option(course, course));
});
},
error: function(error) {
console.log('Error:', error);
}
});
}
// On page load, fetch courses for the pre-selected zone
var defaultZone = $('#zone').val(); // Get the default selected zone
loadCourses(defaultZone); // Load courses for the default zone
// When the zone dropdown changes, fetch the filtered courses
$('#zone').change(function() {
var selectedZone = $(this).val();
loadCourses(selectedZone); // Load courses for the newly selected zone
});
});
|