//jQuery(document).ready(function() { jQuery(document).ready(function() { var isHi = (window.location.pathname.indexOf('/hi/') !== -1); // Get the value of the first option that has a value var firstOptionValue = jQuery('#options option:eq(1)').val(); // Set this value as the selected value of the select element jQuery('#options').val(firstOptionValue).change(); // Show the loader var firstNonDisabledValue = jQuery('#options option:not(:disabled)').eq(0).val(); //alert(firstNonDisabledValue); jQuery.ajax({ type: 'POST', url: ajax_object.ajaxurl, data: { action: 'fetch_data_event', isHindi: isHi, financialYearId: firstNonDisabledValue }, success: function(response) { jQuery('#optionsEvent').html(response); // Get the value of the first option that has a value var firstEventValue = jQuery('#optionsEvent option:eq(1)').val(); // Set this value as the selected value of the select element jQuery('#optionsEvent').val(firstEventValue).change(); }, error: function(xhr, status, error) { console.error(error); alert('An error occurred while fetching data.'); } }); jQuery('#options').change(function() { var selectedValue = jQuery(this).val(); jQuery('.thumbnail-container').html(""); jQuery('#mainImage').attr('src', "https://smp.smportkolkata.in/smpk/wp-content/plugins/custom-plugin-for-all/assets/imgs/custom-gallery-images/original.jpg"); jQuery.ajax({ type: 'POST', url: ajax_object.ajaxurl, data: { action: 'fetch_data_event', isHindi: isHi, financialYearId: selectedValue }, success: function(response) { jQuery('#optionsEvent').html(response); jQuery("#optionsEvent").each(function() { let aaa = jQuery(this).find("option:not(:disabled)").first(); if (aaa.length) { aaa.prop("selected", true); jQuery(this).trigger("change"); // Fire the change event } }); }, error: function(xhr, status, error) { console.error(error); alert('An error occurred while fetching data.'); } }); }); jQuery('#optionsEvent').change(function() { var selectedValue = jQuery(this).val(); var financialYearId = jQuery('#options').val(); jQuery('.loader').show(); jQuery('.thumbnail-container').html(""); jQuery('#mainImage').attr('src', "https://smp.smportkolkata.in/smpk/wp-content/plugins/custom-plugin-for-all/assets/imgs/custom-gallery-images/original.jpg"); jQuery.ajax({ type: 'POST', url: ajax_object.ajaxurl, data: { action: 'fetch_data_image', isHindi: isHi, eventId: selectedValue, financialYearId: financialYearId }, success: function(response) { jQuery('.loader').hide(); jQuery('.thumbnail-container').html(response); // Function to update the main image //function updateMainImage() { var images = jQuery('.thumbnail img'); if (images.length > 0) { var firstImage = images.first(); var newImageSrc = firstImage.data('image'); jQuery('#mainImage').attr('src', newImageSrc); } //} }, error: function(xhr, status, error) { jQuery('.loader').hide(); console.error(error); alert('An error occurred while fetching data.'); } }); }); // Use event delegation to handle dynamically created thumbnails jQuery(document).on('click', '.thumbnail img', function() { var newImage = jQuery(this).data('image'); jQuery('#mainImage').attr('src', newImage); }); });