$(document).ready(function() {
// Select the button using its class
$('.wt_gc_product_as_gift_add_to_cart_btn').on('click', function(event) {
// Get the 'languages' input field
const languageField = $('#languages');
// Check if the field exists
if (languageField.length) {
// Validate if the field is empty
if ($.trim(languageField.val()) === '') {
// Show alert or any other validation message
alert('The languages field is required.');
// Prevent form submission and return false
event.preventDefault();
return false;
}
} else {
console.error('The languages field does not exist.');
}
});
});
document.addEventListener('DOMContentLoaded', function() {
console.log('Button clicked');
const addToCartButton = document.querySelector('.wt_gc_product_as_gift_add_to_cart_btn');
// Check if the button exists
if (addToCartButton) {
console.log('Button found, adding event listener');
addToCartButton.addEventListener('click', function(event) {
// Get the 'languages' input field
const languageField = document.getElementById('languages');
// Check if the field exists
if (languageField) {
console.log('Languages field found');
// Validate if the field is empty
if (languageField.value.trim() === '') {
// Show alert or any other validation message
alert('The languages field is required.');
// Prevent form submission and return false
event.preventDefault();
return false;
}
} else {
console.error('The languages field does not exist.');
}
});
} else {
console.error('Button not found.');
}
});